Blogger Information
Blog 142
fans 5
comment 0
visits 129518
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
支持成功回调
php开发大牛
Original
769 people have browsed it

通过前端jsApiCall()函数可以监听支付结果,但是这个并不可信。确认是否支付成功还是应当通过notify.php 处理业务逻辑。前边配置好了支付验证链接SetNotify_url(),支付完成后,微信服务器会根据链接自动请求你的notify.php文件,打开这个文件,其实这个文件最主要的代码就两行:

$notify = new PayNotifyCallBack();
$notify->Handle(false);

由此跟踪到WxPay.Notify.php类文件的Handle()函数:

/**
*
* 回调入口
* @param bool $needSign 是否需要签名输出
*/
final public function Handle($needSign = true)
{
$msg = "OK";
//当返回false的时候,表示notify中调用NotifyCallBack回调失败获取签名校验失败,此时直接回复失败
$result = WxpayApi::notify(array($this, 'NotifyCallBack'), $msg);
if($result == false){
 $this->SetReturn_code("FAIL");
 $this->SetReturn_msg($msg);
 $this->ReplyNotify(false);
 return;
} else {
 //该分支在成功回调到NotifyCallBack方法,处理完成之后流程
 $this->SetReturn_code("SUCCESS");
 $this->SetReturn_msg("OK");
}
$this->ReplyNotify($needSign);
}

主要代码:

$result = WxpayApi::notify(array($this, 'NotifyCallBack'), $msg);

然后来到WxPay.Api.php文件的第411行,notify()函数:

/**
*
* 支付结果通用通知
* @param function $callback
* 直接回调函数使用方法: notify(you_function);
* 回调类成员函数方法:notify(array($this, you_function));
* $callback 原型为:function function_name($data){}
*/
public static function notify($callback, &$msg)
{
//获取通知的数据
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
//file_put_contents('log.txt',$xml,FILE_APPEND);
//如果返回成功则验证签名
try {
 $result = WxPayResults::Init($xml);
} catch (WxPayException $e){
 $msg = $e->errorMessage();
 return false;
}
 
return call_user_func($callback, $result);
}

这里面的$xml=$GLOBALS['HTTP_RAW_POST_DATA'],就是支付成功后用户返回给你的一个结果,他是一个xml格式的字符串。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!