Jsapi支付

This commit is contained in:
2026-01-23 10:35:46 +08:00
parent 5bde9a9de4
commit e2f25286c6
2 changed files with 154 additions and 1 deletions

View File

@@ -22,7 +22,7 @@ class Payment extends Controller
* APP支付
*/
public function app_pay() {
$type = input('type', 0); //1-微信 2-支付宝 4-通联支付宝 5-通联微信 6-苹果支付
$type = input('type', 0); //1-微信 2-支付宝 4-通联支付宝 5-通联微信 6-苹果支付 7-JSAPI支付
$user_id = input('user_id', 0);
$money = input('money', 0);
$coin = input('coin', 0);
@@ -430,4 +430,62 @@ class Payment extends Controller
return false;
}
//微信JSAPI支付
public function pay_jsapi(){
$user_code = input('user_code');
$money = input('money', 0);
$coin = $money * get_system_config_value('rmb_coin_ratio');
if (!$user_code) {
return V(0, '请选择充值用户', null);
}
if (!is_numeric($money) || floor($money) != $money || $money <= 0 || $money > 5000) {
return V(0, '请选择正确的充值金额', null);
}
$user_id = db::name('user')->where(["user_code" => $user_code])->value('id');
//获取用户的手机号
$user_phone = db::name('user')->where(["id" => $user_id])->value('mobile');
if(!$user_phone){
return V(0, '请先绑定手机号!', null);
}
//获取用户的实名信息
$real_name = db::name('user_auth')->where(["mobile" => $user_phone,'is_real' => 1])->find();
if(!$real_name){
return V(0, '请先实名认证', null);
}
//获取用户的年龄
if(!getAgeId($real_name['card_id'])){
return V(0, '未成年不可充值!', null);
}
$title = '充值到app用户'. $user_code ."余额!";
$order_number = $this->createOrderSn();
$data['order_sn'] = $order_number;
$data['money'] = $money;
$data['user_id'] = $user_id;
$data['pay_type'] = 7; //JSAPI支付
$data['coin'] = $coin;
$data['createtime'] = time();
$data['remarke'] = $title;
$re = db::name('vs_user_recharge')->insert($data);
if (!$re) {
return V(0, '充值失败', null);
}
//引用微信sdk
Loader::import('WxPay.WxPay', EXTEND_PATH, '.php');
$wx = new \WxPay();
// $result = $wx->WxPayMp($data);
$result = $wx->WxPayJsapi($data);
return V(1, 'app支付', $result);
}
}