php WeChat payment callback url
大家讲道理
大家讲道理 2017-06-26 10:49:04
0
3
1162

When should the callback url be written? The document does not explain this in detail. WeChat will only access the callback url if the customer's payment is successful. If the payment fails, it will not access it.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
Ty80

I think you may not have read the document carefully. Attached is the relevant payment business process sequence diagram.

This sequence diagram explains clearly: after the user confirms the payment and enters the password, and the WeChat verification authorization is successful, the merchant will be notified of the payment result asynchronously (note that this includes two situations: successful payment and failed payment) , merchants update their order business logic based on the parameters returned by WeChat.

某草草

After you make the payment on your mobile phone and see that the payment is completed, this can only be regarded as the first step. The callback will not be performed until the payment is completed, which means that the payment transaction flow is pushed to the callback interface.

 public function noticeFirst() {

        Vendor('WXPAYS.lib.WxPayPubHelper');
        $notify = new \Notify_pub();

        //存储微信的回调
        $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
        $notify->saveData($xml);
        $arr = $notify->data;


        //验证签名,并回应微信。
        //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
        //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
        //尽可能提高通知的成功率,但微信不保证通知最终能成功。
        $wxpay_config = array(
            'APPID' => '',
            'MCHID' => '',
            'KEY' => '',
            'APPSECRET' => ''
        );
        if ($notify->checkSign($wxpay_config) === FALSE) {
            $notify->setReturnParameter("return_code", "FAIL"); //返回状态码
            $notify->setReturnParameter("return_msg", "签名失败"); //返回信息
        } else {
            $notify->setReturnParameter("return_code", "SUCCESS"); //设置返回码
        }
        $returnXml = $notify->returnXml();
        echo $returnXml;

        //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
        if ($notify->checkSign($wxpay_config) === TRUE) {

            if ($arr["return_code"] == "FAIL") {
                
            } elseif ($arr["result_code"] == "FAIL") {
                
            } else {

                $info = M('order')->where(array('order_sn' => $arr['out_trade_no']))->find();

                if (!$info) {
                    exit('订单信息有误');
                }
                /* 修改订单状态 */
                $data['status'] = 1;
                $time_end = substr($arr['time_end'], 0, 4) . '-' . substr($arr['time_end'], 4, 2) . '-' . substr($arr['time_end'], 6, 2) . ' ' . substr($arr['time_end'], 8, 2) . ':' . substr($arr['time_end'], 10, 2). ':' . substr($arr['time_end'], 12, 2);
                $data['pay_time'] = strtotime($time_end);
                M('order')->where(array('order_id' => $info['order_id']))->save($data);
                $total_fee=$arr['total_fee'];
                       
                /* 添加支付流水 */
                $_data['appid'] = $arr['appid'];
                $_data['bank_type'] = $arr['bank_type'];
                $_data['cash_fee'] = $arr['cash_fee'];
                $_data['fee_type'] = $arr['fee_type'];
                $_data['is_subscribe'] = $arr['is_subscribe'];
                $_data['mch_id'] = $arr['mch_id'];
                $_data['openid'] = $arr['openid'];
                $_data['out_trade_no'] = $arr['out_trade_no'];
                $_data['result_code'] = $arr['result_code'];
                $_data['return_code'] = $arr['result_code'];
                $_data['total_fee'] = $total_fee;
                $_data['trade_type'] = $arr['trade_type'];
                $_data['transaction_id'] = $arr['transaction_id'];
                $_data['nonce_str'] = $arr['nonce_str'];
                $_data['sign'] = $arr['sign'];
                $_data['time_end'] = $arr['time_end'];
                $pay_flow_id=M('payment_flow')->add($_data);
                
                /* 添加财务流水 */
                //订单ID
                $_trans_data['order_id']=$info['order_id'];
                //会员ID
                $_trans_data['user_id']=$info['user_id'];
                //交易流水号
                $_trans_data['flow_id']=$pay_flow_id;
                //交易类型
                $_trans_data['trans_type']='1';
                //交易渠道
                $_trans_data['trans_channel']='1';
                $_trans_data['amount']=$total_fee*0.01;
                $_trans_data['add_time']=time();
                M('trans_flow')->add($_trans_data);
               
            }

            //商户自行增加处理流程,
            //例如:更新订单状态
            //例如:数据库操作
            //例如:推送支付完成信息
        }
    }

学习ing

Yes, set the callback url when paying. After the payment is successful, WeChat will actively call this url and then process the logic of updating the order

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template