首页  >  文章  >  后端开发  >  thinkphp3.2.3如何对接新版支付宝的示例代码分享

thinkphp3.2.3如何对接新版支付宝的示例代码分享

黄舟
黄舟原创
2017-09-02 09:55:212593浏览

新版支付宝签名验证都是封装好的,只需要配置和调用
thinkphp3.2.3如何对接新版支付宝的示例代码分享

public function pay(){
        //商户订单号,商户网站订单系统中唯一订单号,必填
        $out_trade_no = '27201'.date('YmdHis',time());
        //订单名称,必填
        $proName = trim($_POST['WIDsubject']);
        //付款金额,必填
        $total_amount = '0.01';//trim($_POST['WIDtotal_amount']);
        //商品描述,可空
        $body = '27201';//trim($_POST['WIDbody']);
        Vendor('Alipay.aop.AopClient');
        Vendor('Alipay.aop.request.AlipayTradePagePayRequest');
        //请求
        $c = new \AopClient();
        $config = C('alipay');
        $c->gatewayUrl = "https://openapi.alipay.com/gateway.do";
        $c->appId = $config['app_id'];
        $c->rsaPrivateKey = $config['merchant_private_key'];
        $c->format = "json";
        $c->charset= "UTF-8";
        $c->signType= "RSA2";
        $c->alipayrsaPublicKey = $config['alipay_public_key'];
        $request = new \AlipayTradePagePayRequest();
        $request->setReturnUrl($config['return_url']);
        $request->setNotifyUrl($config['notify_url']);
        $request->setBizContent("{" .
            "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," .
            "    \"subject\":\"$proName\"," .
            "    \"out_trade_no\":\"$out_trade_no\"," .
            "    \"total_amount\":$total_amount," .
            "    \"body\":\"$body\"" .
            "  }");
        $result = $c->pageExecute ($request);
        $model = M('c_house_order');
        $data = array(
            'product_name'=>$proName,
            'order_num'=>$out_trade_no,
            'total_amount'=>$total_amount,
            'description'=>$body,
            'user_id'=>1,
            'add_time'=>NOW_TIME,
            'up_time'=>NOW_TIME
        );
        $model->add($data);
        //输出
        echo $result;
    }

异步通知,直接在你异步通知的方法里面写逻辑,用$_POST去接收支付宝端传过来的参数,进行相对应的数据库插入或者更新。thinkphp3.2.3如何对接新版支付宝的示例代码分享

thinkphp3.2.3如何对接新版支付宝的示例代码分享

以上是thinkphp3.2.3如何对接新版支付宝的示例代码分享的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn