关于(nweb)非微信浏览器回调并查询订单

来源:互联网 发布:火箭队数据 编辑:程序博客网 时间:2024/06/05 23:55

nweb非微信浏览器H5支付 - 查询订单:https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_2&index=2

//支付回调public function h5notify(){$xml = $GLOBALS['HTTP_RAW_POST_DATA'];$arr = json_decode(json_encode(simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOCDATA)),TRUE);$out_trade_no = $arr['out_trade_no'];$transaction_id = $arr['transaction_id'];$where=array('trade'=>$out_trade_no,);$rst=D('trade')->where($where)->setField('transaction_id',$transaction_id);if($rst){$return = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";ob_clean();echo $return;$this->queryOrder($transaction_id);exit;}}
//查询订单private function queryOrder($transaction_id){$appid = "xxxxxx";//微信给的        $mch_id = "1234567890";//微信官方的       $key = "xxxxxxxx";//自己设置的微信商家key        $nonce_str=MD5($out_trade_no);//随机字符串        $rand = rand(00000,99999);        $out_trade_no = date('YmdHis').$rand;//平台内部订单号        $signA="appid=$appid&mch_id=$mch_id&nonce_str=$nonce_str&transaction_id=$transaction_id";        $strSignTmp=$signA."&key=$key";        $sign=strtoupper(md5($strSignTmp));        $url="https://api.mch.weixin.qq.com/pay/orderquery";        $post_data="<xml><appid>$appid</appid><mch_id>$mch_id</mch_id><nonce_str>$nonce_str</nonce_str><transaction_id>$transaction_id</transaction_id><sign>$sign</sign>        </xml>";       $dataxml=$this->http_post($url,$post_data);        $objectxml=(array)simplexml_load_string($dataxml, 'SimpleXMLElement', LIBXML_NOCDATA);       $state=strtolower($objectxml['trade_state']);        if($state == 'success'){        $Trade = D('trade');        $where=array(        'transaction_id'=>$transaction_id        );        $Trade->where($where)->setField('dealtime',time());        $Trade->where($where)->setField('state','1');       }}