yzms/show/appletpay_recv.php

120 lines
4.5 KiB
PHP
Raw Normal View History

<?
if(!$wxpay_recvxml) {
require_once(dirname(__FILE__)."/common.php");
$xmls = file_get_contents("php://input");
} else {
$xmls = $wxpay_recvxml;
}
/*$xmls = "
<xml><appid><![CDATA[wxe2fcb7edf7f486e1]]></appid>
<bank_type><![CDATA[OTHERS]]></bank_type>
<cash_fee><![CDATA[1]]></cash_fee>
<fee_type><![CDATA[CNY]]></fee_type>
<is_subscribe><![CDATA[N]]></is_subscribe>
<mch_id><![CDATA[1673517104]]></mch_id>
<nonce_str><![CDATA[dd69bd18080e98ab076488ccc37b8819]]></nonce_str>
<openid><![CDATA[oCzar63sIJh1F62-z0mOMS4FkPGA]]></openid>
<out_trade_no><![CDATA[FTDC20240415396334855428]]></out_trade_no>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<sign><![CDATA[92CEE54CA3E4392E7B0A3D8279B582BB]]></sign>
<time_end><![CDATA[20240415165129]]></time_end>
<total_fee>1</total_fee>
<trade_type><![CDATA[JSAPI]]></trade_type>
<transaction_id><![CDATA[4200002207202404151893470332]]></transaction_id>
</xml>
";*/
//if(!$xmls) exit;
file_put_contents("appletpay.log", date("Y-m-d H:i:s").": \n".$xmls."\n\n", FILE_APPEND);
$xml = simplexml_load_string($xmls);
if(!$xml) exit;
$data = array();
foreach($xml->children() as $name => $node) {
$data[$name.""] = $node."";
}
if(!$data) exit;
$out_trade_no = $data['out_trade_no'];
if($out_trade_no) {
$ddInfo = $db->get_one("select a.*, c.company_name, c.applet_key from tb_recharge_pay_weixin a, tb_user b, tb_company c where a.uid=b.id and b.company_id=c.id and a.code = '{$out_trade_no}'");
if(!$ddInfo) exit;
$applet_key = $ddInfo['applet_key'];
}
$db->query("insert into tb_recharge_pay_weixin_recv set bank_type='".$data['bank_type']."',cash_fee='".$data['cash_fee']."',fee_type='".$data['fee_type']."',is_subscribe='".$data['is_subscribe']."',openid='".$data['openid']."',out_trade_no='".$data['out_trade_no']."',result_code='".$data['result_code']."',return_code='".$data['return_code']."',sign='".$data['sign']."',time_end='".$data['time_end']."',total_fee='".$data['total_fee']."',trade_type='".$data['trade_type']."',transaction_id='".$data['transaction_id']."',trade_state='".$data['trade_state']."',trade_state_desc='".addslashes($data['trade_state_desc'])."',err_code='".$data['err_code']."',err_code_des='".$data['err_code_des']."',addtime=now()");
$sign = $data['sign'];
if(!$sign) exit;
unset($data['sign']);
ksort($data);
$s1 = '';
foreach($data as $key => $item) {
if($item != '') {
if($s1 != '') $s1 .= "&";
$s1 .= $key."=".$item;
}
}
$s = $s1. "&key=".$applet_key;
$sign2 = strtoupper(md5($s));
if($sign != $sign2) exit;
$code = $data['out_trade_no'];
$orderInfo = $db->get_one("select * from tb_recharge_pay_weixin where code = '{$code}'");
if(!$orderInfo) exit;
if($orderInfo['state'] == 1) {
if(!$wxrecv_isinclude) {
echo "
<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
</xml>
";
}
exit;
}
$total_fee = round($orderInfo['total_fee']*100);
if($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS' && $data['transaction_id'] && (!$data['trade_state'] || $data['trade_state'] == 'SUCCESS') && $total_fee == $data['total_fee']) {
$db->query("insert into tb_recharge_pay_suc set ORDERSEQ='{$code}', AMOUNT='".$orderInfo['total_fee']."', addtime=now()", 'SILENT');
if($db->affected_rows() == 1) {
require_once("include/pay.inc.php");
//gpay_add_user_account_uid($orderInfo['uid'], $orderInfo['total_fee'], 0, $orderInfo['id'], 3, 1, 2, 0);
$uInfo = $db->get_one("select * from tb_user where id = ".$orderInfo['uid']);
$company_id = $uInfo['company_id'];
$dining_hall_id = $uInfo['dining_hall_id'];
$payInfo = array(
'oid' => $orderInfo['id'],
'rtype' => 1,
'ac_type' => 2,
'recharge_fund_type' => 3,
);
if($company_id == 58) { //韶关小岛考虑supplier_id
$supplier_id = 0;
$dInfo = $db->get_one("select * from tb_dining_hall where id = ".intval($dining_hall_id));
if($dInfo) $supplier_id = intval($dInfo['supplier_id']);
$payInfo['supplier_id'] = $supplier_id;
}
$rs = gpay_add_user_account_uid($orderInfo['uid'], $orderInfo['total_fee'], $payInfo);
$db->query("update tb_recharge_pay_weixin set state=1,suctime=now(),transaction_id='".$data['transaction_id']."' where id=".$orderInfo['id']);
//file_put_contents("1.txt", $_SERVER["HTTP_USER_AGENT"].": ".$UPTRANSEQ."\n\n\n", FILE_APPEND);
if(!$wxrecv_isinclude) {
echo "
<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
</xml>
";
}
}
} else {
$db->query("update tb_recharge_pay_weixin set state=2 where id=".$orderInfo['id']);
}