微信瀏覽器用微信支付的JSAPI。
前面的步驟全部完成,可以成功支付。并且在商戶平臺可以查詢到訂單。
在處理“支付結果通知notify_url”這一步出問題。
我仔細按照檔案做了,但是發現并沒有正常運行(資料庫中相應欄位并沒有修改),不知道哪里出了問題。
<?php
//將xml格式的$response 轉成陣列
$receivexml = json_decode( json_encode( simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA) ), true );
//[a]小程式ID
$appid_xml=$receivexml["appid"];
//[b]bank_type
$bank_type_xml=$receivexml["bank_type"];
//[c]現金支付金額
$cash_fee_xml=$receivexml["cash_fee"];
//[i]是否關注公眾賬號
$is_subscribe_xml=$receivexml["is_subscribe"];
//[m]商戶號
$mch_id_xml=$receivexml["mch_id"];
//[n]隨機字串
$nonce_str_xml=$receivexml["nonce_str"];
//[op]簽名
$openid_xml=$receivexml["openid"];
//[ou]商戶訂單號
$out_trade_no_xml=$receivexml["out_trade_no"];
//[r]業務結果
$result_code_xml=$receivexml["result_code"];
//[ti]支付完成時間
$time_end_xml=$receivexml["time_end"];
//[to]訂單金額
$total_fee_xml=$receivexml["total_fee"];
//[trad]交易型別JSAPI、NATIVE、APP
$trade_type_xml=$receivexml["trade_type"];
//[tran]微信支付訂單號
$transaction_id_xml=$receivexml["transaction_id"];
//[s]簽名
$sign_xml=$receivexml["sign"];
$return_code_xml=$receivexml["return_code"];
$result_code_xml=$receivexml["result_code"];
//拼接待簽名字串
$stringA='appid='.$appid_xml.'&bank_type='.$bank_type_xml.'&cash_fee='.$cash_fee_xml.'&is_subscribe='.$is_subscribe_xml.'&mch_id='.$mch_id_xml.'&nonce_str='.$nonce_str_xml.'&openid='.$openid_xml.'&out_trade_no='.$out_trade_no_xml.'&result_code='.$result_code_xml.'&time_end='.$time_end_xml.'&total_fee='.$total_fee_xml.'&trade_type='.$trade_type_xml.'&transaction_id='.$transaction_id_xml;
//拼接key
$stringSignTemp=$stringA.'&key=******';
//字串MD5加密并改為大寫
$sign=strtoupper(md5($stringSignTemp));
//這里需要增加判斷
if ( $return_code_xml=="SUCCESS" and $result_code_xml=="SUCCESS" and $sign==$sign_xml) {
//這里執行存盤程序,修改資料庫中表的資訊,將微信支付訂單號transaction_id寫入資料庫
return "<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
</xml>";
?>
測驗中,微信支付訂單號transaction_id并沒有寫入資料庫中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/238212.html
標籤:微信開發
