1 ";*/ //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 " "; } 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); if($rs == 'suc'){ // 查询充值是否有赠送金额 $giveUrl = "https://yzms.fsecity.com/api/recharge/get_give_fee"; // 获取用户token $userSession = $db->get_one("select * from tb_session where uid = ".$orderInfo['uid'] . " order by expire_time desc"); $giveApiFee = $data['total_fee']/100; $giveInfo = gquery($giveUrl, array("token"=>$userSession['token'],"fee"=>$giveApiFee)); $giveInfo = json_decode($giveInfo, 1); if($giveInfo['status'] == 1){ $giveFee = $giveInfo['data']['gift_fee']; if($giveFee > 0){ $rechargePayInfo = array( 'admin_id' => 1, 'rtype' => 1, 'ac_type' => 1, 'notes' => '充值赠送', ); if(isset($supplier_id) && !empty($supplier_id)){ $rechargePayInfo['supplier_id'] = $supplier_id; } $r = gpay_add_user_account_uid($orderInfo['uid'], floatval($giveFee), $rechargePayInfo); } } } $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 " "; } } } else { $db->query("update tb_recharge_pay_weixin set state=2 where id=".$orderInfo['id']); }