增加小程序支付 校验接口
Change-Id: I0efdbcddc99bb050aee35f26c292fc15a96b96bd
This commit is contained in:
parent
08e36f88d1
commit
c94f1e1fae
144
show/get.php
144
show/get.php
|
@ -3,17 +3,17 @@ require_once(dirname(__FILE__)."/common.php");
|
|||
$act = trim($_GET['act']);
|
||||
|
||||
//if(!in_array($act,array("hkface_get_face_data","get_face"))) {
|
||||
if($_SERVER["HTTP_GYHFTIPFSDX"]) {
|
||||
if($_SERVER["HTTP_GYHFTIPFSDX"]) {
|
||||
$ip = trim(addslashes(current(explode(',', $_SERVER['HTTP_GYHFTIPFSDX']))));
|
||||
} else {
|
||||
} else {
|
||||
$ip = $_SERVER["REMOTE_ADDR"];
|
||||
}
|
||||
$chk_server_log_table = $db->get_one("show tables like 'tb_show_get_log'");
|
||||
if($chk_server_log_table){
|
||||
}
|
||||
$chk_server_log_table = $db->get_one("show tables like 'tb_show_get_log'");
|
||||
if($chk_server_log_table){
|
||||
$request = serialize($_REQUEST);
|
||||
$sql = "insert into tb_show_get_log set act = '".$act."', ip = '".addslashes($ip)."', request = '".addslashes($request)."', record_datetime = now()";
|
||||
$db->query($sql);
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
if($act == 'getTakeCount') {
|
||||
|
@ -202,6 +202,138 @@ if($act == 'wxpay_unifiedorder') {
|
|||
exit;
|
||||
}
|
||||
|
||||
if($act == 'applet_unifiedorder') {
|
||||
$type = $_GET['type'];
|
||||
$isjsapi = ($type == 'jsapi' || strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger'));
|
||||
$user = check_token();
|
||||
$uid = $user['id'];
|
||||
//$uid = 3;
|
||||
$total_fee = round(floatval($_GET['total_fee'])*100);
|
||||
if($total_fee <= 0) exit;
|
||||
|
||||
$company_id = $user['company_id'];
|
||||
if(!$company_id) exit;
|
||||
$cInfo = $db->get_one("select * from tb_company where id=". $company_id);
|
||||
if(!$cInfo) exit;
|
||||
|
||||
|
||||
$applet_mch_id = $cInfo['wxpay_mch_id'];
|
||||
$applet_appid = $cInfo['wxpay_appid'];
|
||||
$applet_key = $cInfo['wxpay_key'];
|
||||
|
||||
if(!$applet_mch_id || !$applet_appid || !$applet_key) {
|
||||
echoRs(0, '不支持小程序支付!');
|
||||
}
|
||||
|
||||
$openid = '';
|
||||
if($isjsapi) {
|
||||
$openid = $user['applet_openid'];
|
||||
if(!$openid) {
|
||||
echoRs(0, '非小程序注册用户!不能使用小程序支付!');
|
||||
}
|
||||
}
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
||||
|
||||
$code = get_code('tb_recharge_pay_weixin', 'code', 12, 'num', "FTDC".date("Ymd"));
|
||||
$time_expire = date("YmdHis", time()+600);
|
||||
$data = array();
|
||||
$data['appid'] = $applet_mch_id;
|
||||
$data['body'] = '订餐系统-充值'.($total_fee/100)."元";
|
||||
$data['mch_id'] = $applet_appid;
|
||||
$data['nonce_str'] = md5(time()."_".rand());
|
||||
$data['notify_url'] = "https://yzms.fsecity.com/show/wxpay_recv.php";
|
||||
$data['out_trade_no'] = $code;
|
||||
$data['spbill_create_ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$data['total_fee'] = $total_fee;
|
||||
$data['time_expire'] = $time_expire;
|
||||
$trade_type = $isjsapi?'JSAPI':'MWEB';;
|
||||
$data['trade_type'] = $trade_type;
|
||||
if($openid) $data['openid'] = $openid;
|
||||
// if($wxpay_sub_mch_id) $data['sub_mch_id'] = $wxpay_sub_mch_id;
|
||||
|
||||
ksort($data);
|
||||
$s1 = '';
|
||||
foreach($data as $key => $item) {
|
||||
if($s1 != '') $s1 .= "&";
|
||||
$s1 .= $key."=".$item;
|
||||
}
|
||||
$s1 .= "&key=".$applet_key;
|
||||
$sign = strtoupper(md5($s1));
|
||||
$xml = "<xml>\n";
|
||||
foreach($data as $key => $item) {
|
||||
$xml .= "\t<{$key}>{$item}</{$key}>\n";
|
||||
}
|
||||
$xml .= "\t<sign>".$sign."</sign>\n";
|
||||
$xml .= "</xml>\n";
|
||||
|
||||
$prepay_id = '';
|
||||
$c = gquery("https://api.mch.weixin.qq.com/pay/unifiedorder", $xml);//echo $xml;exit;
|
||||
if($c) {
|
||||
preg_match("/<prepay_id>(.+)<\/prepay_id>/i", $c, $m);
|
||||
if($m[1]) {
|
||||
$prepay_id = str_replace(array('<![CDATA[', ']]>'), '', $m[1]);
|
||||
|
||||
// $mweb_url = '';
|
||||
// preg_match("/<mweb_url>(.+)<\/mweb_url>/i", $c, $m);
|
||||
// if($m[1]) {
|
||||
// $mweb_url = str_replace(array('<![CDATA[', ']]>'), '', $m[1]);
|
||||
// }
|
||||
//
|
||||
// $code_url = '';
|
||||
// preg_match("/<code_url>(.+)<\/>/i", $c, $m);
|
||||
// if($m[1]) {
|
||||
// $code_url = str_replace(array('<![CDATA[', ']]>'), '', $m[1]);
|
||||
// }
|
||||
}
|
||||
}
|
||||
if(!$prepay_id) {
|
||||
echoRs(0, '下单失败!请重试1!');
|
||||
}
|
||||
|
||||
//临时增加redirect_url
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||
// if(!stristr($ua, "android")) $mweb_url.= "&redirect_url=".urlencode($protocol.$host."/m/wx.html");
|
||||
$sql = "insert into tb_recharge_pay_weixin set code='{$code}', trade_type='{$trade_type}', uid={$uid}, prepay_id='{$prepay_id}', total_fee=".($total_fee/100).", time_expire='{$time_expire}', state=0, is_applet=1, addtime=now()";
|
||||
//echo $sql;
|
||||
$db->query($sql, 'SILENT');
|
||||
if($db->affected_rows() != 1) {
|
||||
echoRs(0, '下单失败!请重试2!');
|
||||
}
|
||||
$data = array();
|
||||
// if($isjsapi) {
|
||||
//
|
||||
// $return_url = "https://yzms.fsecity.com/m/recharge.html?code=".$code;
|
||||
// $sign = md5($prepay_id."_".date("Y-m-d")."_vfj389umk9o3");
|
||||
// $data['mweb_url'] = "https://dc.fsecity.com/show/wxpay/ft_pay.php?prepay_id=".urlencode($prepay_id)."&return_url=".urlencode($return_url)."&sign=".$sign;
|
||||
// } else {
|
||||
// $data['mweb_url'] = $mweb_url;
|
||||
// }
|
||||
$data['code'] = $code;
|
||||
// $data['prepay_id'] = $prepay_id;
|
||||
|
||||
$signData['appId'] = $applet_mch_id;
|
||||
$signData['timeStamp'] = time();
|
||||
$signData['nonceStr'] = md5(time()."_".rand());
|
||||
$signData['package'] = "prepay_id=".$prepay_id;
|
||||
$signData['signType'] = "MD5";
|
||||
ksort($signData);
|
||||
$s2 = '';
|
||||
foreach($signData as $key => $item) {
|
||||
if($s2 != '') $s2 .= "&";
|
||||
$s2 .= $key."=".$item;
|
||||
}
|
||||
$s2 .= "&key=".$applet_key;
|
||||
$signData['paySign'] = strtoupper(md5($s2));
|
||||
|
||||
unset($signData['appId']);
|
||||
$data['requestPayment'] = $signData;
|
||||
echoRs(1, 'ok', array('data' => $data));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if($act == 'get_wxpay_status') {
|
||||
$code = trim($_GET['code']);
|
||||
if(!$code) exit;
|
||||
|
|
Loading…
Reference in New Issue