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

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');
       		}
	}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值