Home > Article > Backend Development > PHP code for processing WeChat payment callbacks to change order payment status
The content this article brings to you is about the PHP server APP WeChat payment callback verification signature to change the order payment status. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<?php //处理微信支付回调 $time = time(); $testxml = file_get_contents("php://input"); //接收微信发送的支付成功信息 //file_put_contents('D:\webroot\xianyijie\JK\weixin.txt',$testxml); $result = XMLDataParse($testxml); file_put_contents("D:\webroot\xianyijie\JK\weixin.txt", json_encode($result)."\r\n", FILE_APPEND); //将信息写入txt文件做支付备份 $sign_return = $result['sign']; //如果成功返回了 if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ $key = "商户密钥key"; unset($result['sign']); $sign = appgetSign($result,$key); if($sign == $sign_return) //验证签名 { //这里是验签成功后的sql操作 //如果操作成功 return "<xml><return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> </xml>"; //如果操作失败 return "fail"; } } /* * 格式化参数格式化成url参数 生成签名sign */ function appgetSign($Obj,$appwxpay_key) { foreach ($Obj as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $String = formatBizQueryParaMap($Parameters, false); //echo '【string1】'.$String.'</br>'; //签名步骤二:在string后加入KEY if($appwxpay_key){ $String = $String."&key=".$appwxpay_key; } //echo "【string2】".$String."</br>"; //签名步骤三:MD5加密 $String = md5($String); //echo "【string3】 ".$String."</br>"; //签名步骤四:所有字符转为大写 $result_ = strtoupper($String); //echo "【result】 ".$result_."</br>"; return $result_; } //xml格式数据解析函数 function XMLDataParse($data){ $xml = simplexml_load_string($data,NULL,LIBXML_NOCDATA); $array=json_decode(json_encode($xml),true); return $array; } ?>
Recommended related articles:
POST and GET request codes in curl of php
About PHP intermediate keys Analysis
The above is the detailed content of PHP code for processing WeChat payment callbacks to change order payment status. For more information, please follow other related articles on the PHP Chinese website!