Home >Backend Development >PHP Tutorial >Sample code sharing on how thinkphp3.2.3 connects to the new version of Alipay

Sample code sharing on how thinkphp3.2.3 connects to the new version of Alipay

黄舟
黄舟Original
2017-09-02 09:55:212621browse

The new version of Alipay signature verification is all encapsulated, you only need to configure and call
Sample code sharing on how thinkphp3.2.3 connects to the new version of Alipay

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;
    }

asynchronous notification, directly in your asynchronous notification Write logic in the notification method, use $_POST to receive the parameters passed by Alipay, and perform corresponding database insertion or update. Sample code sharing on how thinkphp3.2.3 connects to the new version of Alipay

Sample code sharing on how thinkphp3.2.3 connects to the new version of Alipay

The above is the detailed content of Sample code sharing on how thinkphp3.2.3 connects to the new version of Alipay. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn