conf = Db::name('pay_config')->field('mchid,secret,client_cert,client_key,wx_appid_app')->find(['channel' => 2]); self::$instance = Builder::factory([ // 商户号 'mchid' => $this->conf['mchid'], // 商户证书序列号 'serial' => '1DDE55AD98ED71D6EDD4A4A16996DE7B47773A8C', // 商户API私钥 PEM格式的文本字符串或者文件resource 'privateKey' => PemUtil::loadPrivateKey($this->conf['client_key']), 'certs' => [ // 可由内置的平台证书下载器 `./bin/CertificateDownloader.php` 生成 '70A461D25B263BC673B2D9DE98BA8E5706820409' => PemUtil::loadCertificate($this->conf['client_cert']) ], ]); } /** * 微信下单 * @param array $param * @return array */ public function unifiedOrder (array $param) { try { $resp = self::$instance->chain('v3/pay/transactions/app')->post(['json' => [ 'mchid' => $this->conf['mchid'], 'out_trade_no' => $param['out_trade_no'], 'appid' => $this->conf['wx_appid_app'], 'description' => $param['body'], 'notify_url' => env('app.base_url') . 'payResult/wechat', // 支付通知地址, 'amount' => [ 'total' => $param['total_amount'], 'currency' => 'CNY' ], ]]); return ['flag' => true, 'msg' => '调用成功', 'data' => json_decode($resp->getBody())]; } catch (\Throwable $e) { return ['flag' => false, 'msg' => "调用失败," . $e->getMessage() . PHP_EOL]; } } public function checkSign () { } }