$cx_mch_id, 'is_delete' => 0 ]); if(!$wechat_app){ throw new \Exception("小程序信息尚未配置"); } if (!is_dir(\Yii::$app->runtimePath . '/pem')) { mkdir(\Yii::$app->runtimePath . '/pem'); file_put_contents(\Yii::$app->runtimePath . '/pem/index.html', ''); } $cert_pem_file = null; if ($wechat_app->cert_pem) { $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_app->cert_pem); if (!file_exists($cert_pem_file)) file_put_contents($cert_pem_file, $wechat_app->cert_pem); } $key_pem_file = null; if ($wechat_app->key_pem) { $key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_app->key_pem); if (!file_exists($key_pem_file)) file_put_contents($key_pem_file, $wechat_app->key_pem); } $wechat_mp = new Wechat([ 'appId' => $wechat_app->app_id, 'appSecret' => $wechat_app->app_secret, 'mchId' => $wechat_app->mch_id, 'apiKey' => $wechat_app->key, 'certPem' => $cert_pem_file, 'keyPem' => $key_pem_file, 'apiKey_three' => $wechat_app->key_three, ]); return $wechat_mp; } /** * 获取银联支付 * @param integer $cx_mch_id 平台商户ID * return @Updc * @throws Exception */ public function getUpdcService($cx_mch_id = 0, $is_https = true, $algorithm = \Updc\bean\Algorithm::SHA256withRSA) { $res = PaymentConfig::getPaymentConfig(SysConst::$cxPayTypeEnUnionpay, $cx_mch_id); if($res['code'] != 0){ throw new \Exception($res['msg']); } $payment_config = $res['data']; $updc = new \Updc\Updc([ 'appId' => $payment_config['app_id'], 'mchId' => $payment_config['mch_id'], 'url' => $payment_config['api_url'], 'privateKeyPassword' => $payment_config['private_key_password'], 'privateKey' => $payment_config['private_key_pem_file'], 'publicKey' => $payment_config['public_key_pem_file'], 'isHttps' => $is_https, 'algorithm' => $algorithm, ]); return $updc; } }