微信回调问题

<?php
$xml_weixin = file_get_contents('php://input');
$app=str_replace("<![CDATA[", "", $xml_weixin);
$app=str_replace("]]>", "", $app);
$xml_array=simplexml_load_string($app);
$json=json_encode($xml_array);
$me=json_decode($json,true);
file_put_contents('11.txt', $me);
//file_put_contents('11.txt', $me);
$appid = $me['appid'];//应用ID
$bank_type = $me['bank_type'];//付款银行
$cash_fee = $me['cash_fee'];//现金支付金额
$fee_type = $me['fee_type'];//货币种类
$is_subscribe = $me['is_subscribe'];//是否关注公众账号
$mch_id = $me['mch_id'];//商户号
$nonce_str = $me['nonce_str'];//随机字符串
$openid = $me['openid'];//用户标识
$out_trade_no = $me['out_trade_no'];//商户订单号
$result_code = $me['result_code'];//业务结果
$return_code = $me['return_code'];//返回状态码
$sign = $me['sign'];//签名
$time_end = $me['time_end'];//支付完成时间
$total_fee = $me['total_fee'];//总金额
$trade_type = $me['trade_type'];//交易类型
$transaction_id = $me['transaction_id'];//微信支付订单号

//post传递的数据值
$post_data['appid'] = $appid;
$post_data['bank_type'] = $bank_type;
$post_data['cash_fee'] = $cash_fee;
$post_data['fee_type'] = $fee_type;
$post_data['is_subscribe'] = $is_subscribe;
$post_data['mch_id'] = $mch_id;
$post_data['nonce_str'] = $nonce_str;
$post_data['openid'] = $openid;
$post_data['out_trade_no'] = $out_trade_no;
$post_data['result_code'] = $result_code;
$post_data['return_code'] = $return_code;
$post_data['sign'] = $sign;
$post_data['time_end'] = $time_end;
$post_data['total_fee'] = $total_fee;
$post_data['trade_type'] = $trade_type;
$post_data['transaction_id'] = $transaction_id;

$url = '';//调取接口匹对数据
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//用post方法传送参数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

?>

调取的接口中可以做二次签名

public function wxmessage(Request $request){
$appid = $request->input('appid');//应用ID
$bank_type = $request->input('bank_type');//付款银行
$cash_fee = $request->input('cash_fee');//现金支付金额
$fee_type = $request->input('fee_type');//货币种类
$is_subscribe = $request->input('is_subscribe');//是否关注公众账号
$mch_id = $request->input('mch_id');//商户号
$nonce_str = $request->input('nonce_str');//随机字符串
$openid = $request->input('openid');//用户标识
$out_trade_no = $request->input('out_trade_no');//商户订单号
$result_code = $request->input('result_code');//业务结果
$return_code = $request->input('return_code');//返回状态码
$sign = $request->input('sign');//签名
$time_end = $request->input('time_end');//支付完成时间
$total_fee = $request->input('total_fee');//总金额
$trade_type = $request->input('trade_type');//交易类型
$transaction_id = $request->input('transaction_id');//微信支付订单号

//进行二次签名认证
if($result_code == 'SUCCESS' && $return_code == 'SUCCESS'){
$params = array(); //参加验签签名的参数数组
$params['appid'] = $appid;
$params['bank_type'] = $bank_type;
$params['cash_fee'] = $cash_fee;
$params['fee_type'] = $fee_type;
$params['is_subscribe'] = $is_subscribe;
$params['mch_id'] = $mch_id;
$params['nonce_str'] = $nonce_str;
$params['openid'] = $openid;
$params['out_trade_no'] = $out_trade_no;
$params['result_code'] = $result_code;
$params['return_code'] = $return_code;
$params['time_end'] = $time_end;
$params['total_fee'] = $total_fee;
$params['trade_type'] = $trade_type;
$params['transaction_id'] = $transaction_id;

$verify_sign = $wechatAppPay->MakeSign($params);//生成验签签名
if($verify_sign == $sign){
$wechatAppPay->replyNotify();//商户处理后同步返回给微信参数
}else{
return false;
}
// $wechatAppPay->replyNotify();//商户处理后同步返回给微信参数
}else{
return false;
}

}

 注意:也可以在一个php里面写,最好是一级域名和开放平台设置的一致,不然会很多坑的

原文地址:https://www.cnblogs.com/zhangmeilin/p/7326673.html