$tradeType = "APP"; // JSAPI
$accountPayment = [
'APP' => [
'app_id' => 'app_id',
'mch_id' => 'mch_id',
'key' => 'XXXXXXXXXXXXXXXXXXXXXXX',
'cert_path' => app_path('resources/cert/apiclient_cert.pem'),
'key_path' => app_path('resources/cert/apiclient_key.pem'),
'notify_url' => route('weChatNotifyUrl'),
],
'JSAPI' => [
'app_id' => 'app_id',
'mch_id' => 'mch_id',
'key' => 'XXXXXXXXXXXXXXXXXXXXXXX',
'cert_path' => app_path('resources/cert2/apiclient_cert.pem'),
'key_path' => app_path('resources/cert2/apiclient_key.pem'),
'notify_url' => route('weChatNotifyUrl'),
],
];
$app = Factory::payment($accountPayment[$tradeType]);
$order_info = [
'body' => $title,
'out_trade_no' => $order_number,
'total_fee' => $amount,
'trade_type' => $tradeType, // 交易类型 JSAPI | NATIVE |APP | WAP
];
$result = $app->order->unify($order_info);
if ($tradeType == 'JSAPI') { // 微信内H5/小程序支付
$jssdk = $app->jssdk;
$config = $jssdk->bridgeConfig($result['prepay_id'], false);
} else { // APP支付
$config = $app->jssdk->appConfig($result['prepay_id']);
}
微信内H5/小程序支付$config信息
"config": {
"appId": "xxxxx",
"timeStamp": "xxxxx",
"nonceStr": "xxxxx",
"package": "prepay_id=xxxxxx",
"signType": "MD5",
"paySign": "xxxxx"
}
APP支付$config信息
"config": {
"appid": "xxxxx",
"partnerid": "xxxxx",
"prepayid": "xxxxxx",
"noncestr": "xxxxx",
"timestamp": 2022215515,
"package": "Sign=WXPay",
"sign": "xxxxxxxx"
}