微信公众号支付
This commit is contained in:
@@ -29,19 +29,22 @@ class WechatPayService
|
||||
protected ?Application $application = null;
|
||||
|
||||
/**
|
||||
* 统一下单(小程序 JSAPI)
|
||||
* 统一下单(JSAPI:小程序 / 公众号 H5 通用)
|
||||
*
|
||||
* @param string $paymentNo 商户订单号(本系统支付单号)
|
||||
* @param string $amountYuan 金额(元,两位小数)
|
||||
* @param string $openid 付款人 openid
|
||||
* @param string $openid 付款人 openid(按下单 appid 维度:小程序 openid 或公众号 openid)
|
||||
* @param string $description 订单标题
|
||||
* @return array<string, mixed> wx.requestPayment 调起参数(timeStamp/nonceStr/package/signType/paySign)
|
||||
* @param string $appid 下单应用 appid(公众号 JSAPI 传公众号 appid;留空取配置的小程序 appid)
|
||||
* @return array<string, mixed> 调起支付参数(appId/timeStamp/nonceStr/package/signType/paySign,
|
||||
* 小程序喂 wx.requestPayment,公众号 H5 喂 WeixinJSBridge getBrandWCPayRequest,结构同构)
|
||||
* @throws RepositoryException 未配置或下单失败
|
||||
*/
|
||||
public function createOrder(string $paymentNo, string $amountYuan, string $openid, string $description): array
|
||||
public function createOrder(string $paymentNo, string $amountYuan, string $openid, string $description, string $appid = ''): array
|
||||
{
|
||||
$appid = trim($appid) !== '' ? trim($appid) : $this->appid();
|
||||
$result = $this->call('POST', '/v3/pay/transactions/jsapi', [
|
||||
'appid' => $this->appid(),
|
||||
'appid' => $appid,
|
||||
'mchid' => $this->config('mch_id'),
|
||||
'description' => mb_substr($description, 0, 127),
|
||||
'out_trade_no' => $paymentNo,
|
||||
@@ -59,8 +62,9 @@ class WechatPayService
|
||||
throw new RepositoryException('微信支付下单失败:应答缺少 prepay_id');
|
||||
}
|
||||
|
||||
$params = $this->app()->getUtils()->buildMiniAppConfig($prepayId, $this->appid());
|
||||
Log::driver('pay')->info('微信支付下单成功', ['out_trade_no' => $paymentNo, 'prepay_id' => $prepayId]);
|
||||
// buildMiniAppConfig 即 buildBridgeConfig(小程序 wx.requestPayment 与公众号 WeixinJSBridge 参数同构)
|
||||
$params = $this->app()->getUtils()->buildMiniAppConfig($prepayId, $appid);
|
||||
Log::driver('pay')->info('微信支付下单成功', ['out_trade_no' => $paymentNo, 'prepay_id' => $prepayId, 'appid' => $appid]);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user