feat: 微信小程序内支付时,下单接口传递openid
parent
a14bd86005
commit
dc5945960f
|
@ -74,7 +74,11 @@ class Pay extends Api
|
|||
$result = PayLogic::balancePay($post['order_id'], $post['from']);
|
||||
break;
|
||||
case OrderEnum::PAY_WAY_WECHAT://微信支付
|
||||
$result = PayLogic::wechatPay($post['order_id'], $post['from'], $this->client);
|
||||
if (empty($post['openid'])) {
|
||||
//微信支付时必须传openid过来
|
||||
return JsonServer::error('缺少openid');
|
||||
}
|
||||
$result = PayLogic::wechatPay($post['order_id'], $post['from'], $this->client, $post['openid']);
|
||||
break;
|
||||
case OrderEnum::PAY_WAY_ALIPAY://支付宝支付
|
||||
$result = PayLogic::aliPay($post['order_id'], $post['from'],$this->client);
|
||||
|
|
|
@ -68,11 +68,13 @@ class LoginLogic extends Logic
|
|||
return false;
|
||||
}
|
||||
|
||||
// 将openid返回给前端缓存 支付的时候降openid传给后端
|
||||
if (empty($user_id)) {
|
||||
//系统中没有用户-调用authlogin接口生成新用户
|
||||
return [];
|
||||
return ['openid' => $response['openid'] ?? ''];
|
||||
} else {
|
||||
$user_info = UserServer::updateUser($response, Client_::mnp, $user_id);
|
||||
$user_info['openid'] = $response['openid'] ?? '';
|
||||
}
|
||||
|
||||
//验证用户信息
|
||||
|
|
|
@ -296,7 +296,7 @@ class PayLogic extends Logic
|
|||
* @author suny
|
||||
* @date 2021/7/13 6:24 下午
|
||||
*/
|
||||
public static function wechatPay($order_id, $form, $client)
|
||||
public static function wechatPay($order_id, $form, $client, $openid = '')
|
||||
{
|
||||
switch ($form) {
|
||||
case "trade":
|
||||
|
@ -327,7 +327,7 @@ class PayLogic extends Logic
|
|||
return JsonServer::error('订单已支付');
|
||||
}
|
||||
// 这里进行微信支付
|
||||
$res = WeChatPayServer::unifiedOrder($form, $order, $client);
|
||||
$res = WeChatPayServer::unifiedOrder($form, $order, $client, $openid);
|
||||
if (false === $res) {
|
||||
return JsonServer::error(WeChatPayServer::getError());
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ class WeChatPayServer
|
|||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function unifiedOrder($from, $order, $order_source)
|
||||
public static function unifiedOrder($from, $order, $order_source, $openid = '')
|
||||
{
|
||||
|
||||
try {
|
||||
|
@ -99,11 +99,14 @@ class WeChatPayServer
|
|||
//jsapi需要验证openID
|
||||
$check_source = [Client_::mnp, Client_::oa];
|
||||
if (!$auth && in_array($order_source, $check_source)) {
|
||||
throw new Exception('授权信息失效');
|
||||
// throw new Exception('授权信息失效');
|
||||
}
|
||||
|
||||
$app = Factory::payment($config);
|
||||
$attributes = self::getAttributes($from, $order, $order_source, $auth, $notify_url);
|
||||
if (empty($attributes['openid'])) {
|
||||
$attributes['openid'] = $openid;
|
||||
}
|
||||
$result = $app->order->unify($attributes);
|
||||
if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
|
||||
|
||||
|
|
Loading…
Reference in New Issue