/* 生成支付签名*/ private function genPaySign($unifiedOrder, $time) { $appId = \WxPayConfig::APPID; $nonceStr = $unifiedOrder['nonce_str']; $package = 'prepay_id=' . $unifiedOrder['prepay_id']; $signType = "MD5"; $timeStamp = $time; $key = \WxPayConfig::KEY; $sign = md5(sprintf("appId=%s&nonceStr=%s&package=%s&signType=%s&timeStamp=%s&key=%s", $appId, $nonceStr, $package, $signType, $timeStamp, $key)); }
/** * 支付回调 * @author:大脸猫脸大 */ public function payNotify() { import("Vendor.Wxpay.lib.WxPay#Data", "", ".php"); $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $val = \WxPayResults::Init($xml); if ($val['result_code'] == 'SUCCESS' && $val['return_code'] == 'SUCCESS') { $orderSn = $val['out_trade_no']; $transactionId = $val['transaction_id']; $data = array('paytype' => 'weixin', 'status' => '1', 'paytime' => time(), 'paysn' => $transactionId); M("Order")->where("ordersn='$orderSn'")->setField($data); exit('<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>'); }else { Log::write(var_export($val, true), Log::ERR, '', C('LOG_PATH')."wx_pay_notify_".date('y_m_d').'.log'); exit('<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>'); } }
payNotify 回调方法里一定要注意返回
复制代码 代码如下:
<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>
如果不处理,你会发现payNotify 会被执行很多次参见:
总结一下:
注意二点,1.签名的问题 2. 回调方法的返回处理。
欢迎大家指正。