微信公众号支付
This commit is contained in:
@@ -16,10 +16,10 @@ use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 小程序在线支付(渠道二选一:旺铺网关 JSAPI / 微信官方支付 APIv3)
|
||||
* 小程序在线支付(渠道二选一:旺铺网关 JSAPI / 微信官方支付 APIv3;场景二选一:小程序 / 公众号 H5)
|
||||
*
|
||||
* 链路:POST /mini/payment/online 下单(返回调起支付参数)
|
||||
* → 小程序 wx.requestPayment 完成支付
|
||||
* 链路:POST /mini/payment/online 下单(scene=mini 小程序 / scene=mp 公众号,返回调起支付参数)
|
||||
* → 小程序 wx.requestPayment / 公众号 H5 WeixinJSBridge 完成支付
|
||||
* → 渠道后台通知(旺铺 /mini/payment/notify;微信 /mini/payment/wechat-notify)验签 + 幂等结账
|
||||
* → 小程序 GET /mini/payment/online/{paymentNo}/query 主动同步支付结果(回调兜底)
|
||||
*/
|
||||
@@ -33,7 +33,10 @@ class OnlinePaymentController extends BaseMiniController
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 发起在线支付:合并选择本店未支付账单 → 旺铺下单 → 返回调起支付参数
|
||||
* 发起在线支付:合并选择本店未支付账单 → 渠道下单 → 返回调起支付参数
|
||||
*
|
||||
* scene=mini(默认):小程序 wx.login code 换 openid,wx.requestPayment 调起;
|
||||
* scene=mp:公众号 H5 网页授权 code 换 openid,WeixinJSBridge getBrandWCPayRequest 调起。
|
||||
* @throws Throwable
|
||||
*/
|
||||
#[PostRoute('/payment/online', authorize: true)]
|
||||
@@ -43,11 +46,13 @@ class OnlinePaymentController extends BaseMiniController
|
||||
'bill_ids' => 'required|array|min:1',
|
||||
'bill_ids.*' => 'integer|distinct',
|
||||
'code' => 'required|string|max:64',
|
||||
'scene' => 'nullable|string|in:mini,mp',
|
||||
'remark' => 'nullable|string|max:255',
|
||||
], [
|
||||
'bill_ids.required' => '请选择要付款的账单',
|
||||
'bill_ids.min' => '请选择要付款的账单',
|
||||
'code.required' => '微信登录凭证缺失,请重新进入小程序',
|
||||
'code.required' => '微信登录/授权凭证缺失,请重新进入',
|
||||
'scene.in' => '支付场景不正确',
|
||||
'remark.max' => '备注超过最大长度',
|
||||
]);
|
||||
|
||||
@@ -58,6 +63,7 @@ class OnlinePaymentController extends BaseMiniController
|
||||
array_map('intval', $data['bill_ids']),
|
||||
(string) $data['code'],
|
||||
(string) ($data['remark'] ?? ''),
|
||||
(string) ($data['scene'] ?? OnlinePaymentService::SCENE_MINI),
|
||||
);
|
||||
|
||||
return $this->success([
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Exceptions\RepositoryException;
|
||||
use App\Models\BillModel;
|
||||
use App\Models\PaymentModel;
|
||||
use App\Services\BillNumberService;
|
||||
use App\Services\WechatMpService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -48,6 +49,8 @@ class PaymentController extends BaseMiniController
|
||||
'wechat_qrcode' => $resolve(site_config('pay.wechat_qrcode', '')),
|
||||
'alipay_qrcode' => $resolve(site_config('pay.alipay_qrcode', '')),
|
||||
'bank_info' => (string) site_config('pay.bank_info', ''),
|
||||
// 公众号 AppID(H5 在微信内置浏览器拼网页授权链接使用,授权回调 code 传给 /mini/payment/online scene=mp)
|
||||
'mp_appid' => app(WechatMpService::class)->appid(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user