微信支付notify.php回调获取trade_out_no

浏览:2243 发布日期:2018/07/10 分类:技术分享 关键字: 微信支付 out_trade_no notify.php
一开始吧,我用session传trade_out_no,失败,因为微信服务器没有cookie特征值(微信服务器和你的手机是两个客户端。。。)。然后用微信支付结果返回的xml获取trade_out_no,记住,这里有坑,复制微信解析xml的代码,解析要忽略xml注释的。放代码。
$xml = file_get_contents("php://input");

$xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBxml_NOCDATA));//将对象转换个JSON
file_put_contents("json.txt",$xmljson);
$xmlarray=json_decode($xmljson,true);//将json转换成数组



$trade_no=$xmlarray['out_trade_no'];
之后就可以更新订单了。我把更新订单写在这里了WxPayNotify extends WxPayNotifyReply
{
/**
*
* 回调入口
* @param bool $needSign 是否需要签名输出
*/
final public function Handle($needSign = true)
{ $xml = file_get_contents("php://input");
// file_put_contents("e1.txt","阿萨德");
$msg = "OK";
//当返回false的时候,表示notify中调用NotifyCallBack回调失败获取签名校验失败,此时直接回复失败
$result = WxpayApi::notify(array($this, 'NotifyCallBack'), $msg);
if($result == false){
//file_put_contents("e1.txt","1");
$this->SetReturn_code("FAIL");
$this->SetReturn_msg($msg);
$this->ReplyNotify(false);
return;
} else {

//该分支在成功回调到NotifyCallBack方法,处理完成之后流程
$this->SetReturn_code("SUCCESS");
$this->SetReturn_msg("OK");
}
$db=new db_class("localhost:3306","root","123456","yuewen");

$db->db_settablename("think_list");

$typearr[]="status";

$valuearr[]=1;

$xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBxml_NOCDATA));//将对象转换个JSON
file_put_contents("json.txt",$xmljson);
$xmlarray=json_decode($xmljson,true);//将json转换成数组



$trade_no=$xmlarray['out_trade_no'];

$where="trade_no='".$trade_no."'";
file_put_contents("xml2.txt",$xml);
file_put_contents("asl1.txt",$where);
$db->db_update($typearr,$valuearr,$where);
$this->ReplyNotify($needSign);
}

}

重点,我把整个文件夹上传了,你配置lib目录里WxPay.Config.php信息就好了,更新订单要自己改哦。。。

附件 payment.rar ( 181.64 KB 下载:42 次 )

最佳答案
评论( 相关
后面还有条评论,点击查看>>