ThinkPHP5.x 支付宝当面付[扫描用户付款码支付]

前些日子开发的超市收银系统需要对接支付宝当面付和微信的刷卡支付,就看了看文档,整合了进来。下面将支付宝的先分享出来。

版本要求:ThinkPHP5.x

支付宝当面付申请页面:https://b.alipay.com/signing/productDetail.htm?productId=I1011000290000001003

业务流程就不用多说了 ,直接上代码,整合文档在压缩包内,使用过程中遇到问题欢迎交流。Q66770546

_AlipayF2F_ThinkPHP5.X

4 Comments

 Add your comment
  1. //AlipayTradePayContentBuilder.php 需要在官方当面付SDK中下载调用
    // 官方SDK 地址 https://docs.open.alipay.com/54/103419
    /**
    * 二维码当面付
    *
    * @param mixed $sn 自定义订单编号
    * @param string $subject 订单标题
    * @param string $body 订单正文
    * @param number $total_amount 支付金额
    * @return NULL[]
    */
    public static function doQrCodeTrade($sn, $subject, $body, $total_amount)
    {
    $qrPayRequestBuilder = new \AlipayTradePayContentBuilder();
    $qrPayRequestBuilder->setOutTradeNo($sn);
    $qrPayRequestBuilder->setTotalAmount($total_amount);
    //$qrPayRequestBuilder->setAuthCode($auth_code);
    $qrPayRequestBuilder->setTimeExpress(“5m”);
    $qrPayRequestBuilder->setSubject($subject);
    $qrPayRequestBuilder->setBody($body);

    // 调用barPay方法获取当面付应答
    $config = config(‘service.alipay’);
    $qrPay = new \AlipayTradeService($config);
    $qrPayResult = $qrPay->qrPay($qrPayRequestBuilder);

    $data = [];
    $data[‘status’] = $qrPayResult->getTradeStatus(); // SUCCESS/FAILED/UNKNOWN
    $response = json_decode(json_encode($qrPayResult->getResponse()), true);
    trace(‘alipay:’ . json_encode($response), ‘log’);
    $data[‘message’] = $response[‘msg’];
    if ($data[‘status’] == ‘SUCCESS’) {
    $data[‘outer_sn’] = $response[‘trade_no’];
    } else {
    $data[‘message’] .= $response[‘sub_msg’];
    }

    return $data;
    }

    //帮博主多补充一种方式,感谢博主分享

Leave a Comment

Your email address will not be published.

*