微信支付开发交易通知实例

一、交易通知

用户在成功完成支付后,微信后台通知(POST)商户服务器(notify_url)支付结果。商户可以使用notify_url的通知结果进行个性化页面的展示。

后台通知交互时,如果微信收到商户的应答不是success或超时,微信不为通知失败,微信会通过一定的策略(如30分钟共8次)定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。

后台通知通过请求中的 notify_url 迚行,采用 POST 机制。

同时,在postData中还将包含xml数据。

二、交易结果获取与响应

根据官方文档,创建notice.PHP用于通知结果。

程序内容如下所示:

rush:PHP;"> foreach ($_GET as $key=>$value)
{
logger("Key: $key; Value: $value");
}
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
logger($postStr);

if (isset($_GET)){
echo "success";
}

//日志记录
function logger($log_content)
{
$max_size = 100000;
$log_filename = "log.xml";
if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}
file_put_contents($log_filename,date('H:i:s')." ".$log_content."\r\n",FILE_APPEND);
}
?>

上述程序的作用是:

获取post到url的通知,他们以GET变量形式

获取post的XML数据包

返回成功消息 success

将notice.PHP的完整路径放入JS API支付的notice url中。

setParameter("notify_url",http://www.doucube.com/wxpay/notice.PHP);

这样当交易完成后,该url将收到通知,并记录在日志文件中,我们的测试如下所示:

获得的GET变量及XML如下所示:

rush:js;"> Key: bank_billno; Value: 201405273540085997 Key: bank_type; Value: 2011 Key: discount; Value: 0 Key: fee_type; Value: 1 Key: input_charset; Value: GBK Key: notify_id; Value: Gx8ov6tT6_yaARrtKG6RFZ4KiVtKqVnJzvulFlteJ3dhBg38iRtKs0pTXXfgh8WnH15mIhG6j65ggbzzYguh1mutG3B5oHsK Key: out_Trade_no; Value: JfuKdiBig4zZnE4n Key: partner; Value: 1234567890 Key: product_fee; Value: 1 Key: sign; Value: 08876C4A9F7A36A9EA972C211C122362 Key: sign_type; Value: MD5 Key: time_end; Value: 20140527194139 Key: total_fee; Value: 1 Key: Trade_mode; Value: 1 Key: Trade_state; Value: 0 Key: transaction_id; Value: 1218614901201405273313473135 Key: transport_fee; Value: 0 1 1401190899

normal; word-spacing: 0px; text-transform: none; float: none; color: rgb(51,51,51); font: 14px/25px verdana,Arial,Helvetica,sans-serif; widows: 1; display: inline !important; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px">而在微信窗口中将收到OK的弹出窗

以上就是对微信支付开发交易通知的资料整理,谢谢支持

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...