find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } if($user_info['is_real'] != 1){ return ['code' => 201, 'msg' => '请先实名认证', 'data' => null]; } $pay_money = 0; $give_integral = 0; if (!in_array($pay_type, [1, 2, 21])) { return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null]; } //2:原生微信支付 if($pay_type==2){ $app_ys_wx_recharge = get_system_config('app_ys_wx_recharge'); if($app_ys_wx_recharge != 1){ return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null]; } } //20:支付宝原生支付开关 if($pay_type==1){ $app_ys_zfb_recharge = get_system_config('app_ys_zfb_recharge'); if($app_ys_zfb_recharge != 1){ return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null]; } } if ($pay_type == 21) { $zfbh5_huifu_recharge = get_system_config('zfbh5_huifu_recharge'); if($zfbh5_huifu_recharge != 1){ return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null]; } } if (!empty($crid)) { $map = []; $map[] = ['crid', '=', $crid]; $map[] = ['is_delete', '=', 1]; $can_recharge_info = Db::name('can_recharge')->where($map)->find(); if (empty($can_recharge_info)) { return ['code' => 201, 'msg' => '充值金额不存在', 'data' => null]; } if ($can_recharge_info['money'] <= 0) { return ['code' => 201, 'msg' => '充值金额参数非法', 'data' => null]; } $pay_money = $can_recharge_info['money']; $give_integral = $can_recharge_info['integral']; } else { if (intval($custom_amount) != $custom_amount) { return ['code' => 201, 'msg' => '充值金额必须为整数', 'data' => null]; } if ($custom_amount < 1) { return ['code' => 201, 'msg' => '充值金额最少1元', 'data' => null]; } $exchange_rate = get_system_config('exchange_rate'); $pay_money = $custom_amount; $give_integral = $custom_amount * $exchange_rate; } $order_sn = $this->create_recharge_order_sn(1); // $pay_money = 0.01; $data = []; $data['order_sn'] = $order_sn; $data['order_type'] = 1; $data['money'] = $pay_money; $data['integral'] = $give_integral; $data['pay_type'] = $pay_type; $data['uid'] = $uid; $data['pay_status'] = 1; $data['pay_time'] = 0; $data['remarke'] = ''; $data['add_time'] = time(); $data['update_time'] = time(); $data['carry_money'] = $pay_money; $data['is_carray_finish'] = 2; $status = Db::name('user_recharge')->insert($data); $data = []; if ($status) { if ($pay_type == 1) { // $data = $this->threePayFromPost($order_sn, $pay_money, 922); $data = $this->alipayHand($order_sn, $pay_money); } elseif($pay_type == 21){ // $data = model('api/AdaPay')->create_order($order_sn, $pay_money, $uid); // if($data['code'] != 200){ // return ['code' => 201, 'msg' => '支付失败', 'data' => null]; // } // $result = $data['result']; // if(isset($result['status']) && ($result['status'] == "succeeded")){ // $payment_id = $result['id']; // $map = []; // $map[] = ['order_sn', '=', $order_sn]; // $order_info = Db::name('user_recharge')->where($map)->update(['payment_id'=>$payment_id]); // } $data = model('HuiFu1')->ali_h5($order_sn, $pay_money); if(!empty($data['data']['qr_code'])){ return ['code' => 200, 'msg' => '请求成功', 'data' => ['pay_info'=>'alipays://platformapi/startapp?saId=10000007&qrcode='.$data['data']['qr_code']]]; // return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']]; }else{ return ['code' => 201, 'msg' => '支付失败', 'data' => null]; } } else { // $data = $this->threePayFromPost($order_sn, $pay_money, 921); $data = $this->wxpayHand($order_sn, $pay_money); } } return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']]; } //购买会员 public function pay_vip_order($uid, $vid, $pay_type) { $user_info = db::name('user')->find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } $pay_money = 0; $give_integral = 0; if (!in_array($pay_type, [1, 2])) { return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null]; } if(!empty($vid)){ $map = []; $map[] = ['vid', '=', $vid]; $vip_info = db::name('vip')->where($map)->find(); if(empty($vip_info)){ return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null]; } if ($vip_info['price'] <= 0) { return ['code' => 201, 'msg' => '会员卡购买金额参数非法', 'data' => null]; } $pay_money = $vip_info['price']; }else{ return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null]; } $order_sn = $this->create_recharge_order_sn(2); // $pay_money = 0.01; $data = []; $data['order_sn'] = $order_sn; $data['order_type'] = 2; $data['vid'] = $vid; $data['money'] = $pay_money; $data['integral'] = $give_integral; $data['pay_type'] = $pay_type; $data['uid'] = $uid; $data['pay_status'] = 1; $data['pay_time'] = 0; $data['remarke'] = ''; $data['add_time'] = time(); $data['update_time'] = time(); $status = Db::name('user_recharge')->insert($data); $data = []; if ($status) { if ($pay_type == 1) { // $data = $this->threePayFromPost($order_sn, $pay_money, 922); $data = $this->alipayHand($order_sn, $pay_money); } else { // $data = $this->threePayFromPost($order_sn, $pay_money, 921); $data = $this->wxpayHand($order_sn, $pay_money); } } return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']]; } //更换邀请人 public function update_user_inviter($uid, $user_id, $sms_code, $pay_type) { $config = get_uncache_system_config(); $user_info = db::name('user')->where('uid', $uid)->find(); if(!$user_info){ return ['code' => 201, 'msg' => '参数错误', 'data' => null]; } if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } if($user_info['user_name'] == $uid){ return ['code' => 201, 'msg' => '该用户尚未绑定手机号', 'data' => null]; } $reslut = model('sms')->verification_code($user_info['user_name'], $sms_code); if ($reslut['code'] == 201) { return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']); } $pay_money = 0; $give_integral = 0; $inviter_info = db::name('user')->where('uid', $user_id)->find(); if(!$inviter_info){ return ['code' => 201, 'msg' => '更换邀请人不存在', 'data' => null]; } if(empty($inviter_info['vid'])){ return ['code' => 201, 'msg' => '更换邀请人不是会员', 'data' => null]; } if($inviter_info['vip_end_time'] - time() < (60*60*24*30)){ return ['code' => 201, 'msg' => '更换邀请人会员少于30天', 'data' => null]; } if (!in_array($pay_type, [1, 2])) { return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null]; } if(empty($config['update_inviter_price']) && $config['update_inviter_price'] < 0){ return ['code' => 201, 'msg' => '换绑支付金额不能为空且不能小于0', 'data' => null]; } $pay_money = $config['update_inviter_price']; $order_sn = $this->create_recharge_order_sn(3); // $pay_money = 0.01; $data = []; $data['order_sn'] = $order_sn; $data['order_type'] = 3; $data['invite_uid'] = $user_id; $data['money'] = $pay_money; $data['integral'] = $give_integral; $data['pay_type'] = $pay_type; $data['uid'] = $uid; $data['pay_status'] = 1; $data['pay_time'] = 0; $data['remarke'] = ''; $data['add_time'] = time(); $data['update_time'] = time(); $status = Db::name('user_recharge')->insert($data); $data = []; if ($status) { if ($pay_type == 1) { // $data = $this->threePayFromPost($order_sn, $pay_money, 922); $data = $this->alipayHand($order_sn, $pay_money); } else { // $data = $this->threePayFromPost($order_sn, $pay_money, 921); $data = $this->wxpayHand($order_sn, $pay_money); } } return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']]; } public function threePayFromPost( $pay_orderid='', $pay_amount=0, $pay_bankcode='921'){ $pay_memberid = "210879796"; //商户后台API管理获取 //$pay_orderid = 'E'.date("YmdHis").rand(100000,999999); //订单号 //$pay_amount = 10; //交易金额 $pay_applydate = date("Y-m-d H:i:s"); //订单时间 $pay_notifyurl = "http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/three_pay_notify"; //服务端返回地址 $pay_callbackurl = "http://" . $_SERVER['HTTP_HOST']; //页面跳转返回地址 $Md5key = "lsn75mdcbhuy0h913blni0wxycpcq2dk"; //商户后台API管理获取 $tjurl = "https://guohongpay.com//Pay_Index.html"; //提交地址 //$pay_bankcode = "921"; //922 支付宝 921 微信 //商户后台通道费率页 获取银行编码 $native = array( "pay_memberid" => $pay_memberid, "pay_orderid" => $pay_orderid, "pay_amount" => $pay_amount, "pay_applydate" => $pay_applydate, "pay_bankcode" => $pay_bankcode, "pay_notifyurl" => $pay_notifyurl, "pay_callbackurl" => $pay_callbackurl, ); ksort($native); $md5str = ""; foreach ($native as $key => $val) { $md5str = $md5str . $key . "=" . $val . "&"; } //echo($md5str . "key=" . $Md5key); $sign = strtoupper(md5($md5str . "key=" . $Md5key)); $native["pay_md5sign"] = $sign; $native['pay_attach'] = "1234|456"; $native['pay_productname'] ='团购商品'; $html=' '; // echo $html; } //支付宝异步回调 public function three_pay_notify($data) { $returnArray = array( // 返回字段 "memberid" => $data["memberid"], // 商户ID "orderid" => $data["orderid"], // 订单号 "amount" => $data["amount"], // 交易金额 "datetime" => $data["datetime"], // 交易时间 "transaction_id" => $data["transaction_id"], // 支付流水号 "returncode" => $data["returncode"], ); $md5key = "lsn75mdcbhuy0h913blni0wxycpcq2dk"; ksort($returnArray); reset($returnArray); $md5str = ""; foreach ($returnArray as $key => $val) { $md5str = $md5str . $key . "=" . $val . "&"; } $sign = strtoupper(md5($md5str . "key=" . $md5key)); if ($sign == $data["sign"]) { if ($data["returncode"] == "00") { $order_sn = $data['orderid']; $pay_amount = $data['amount']; $data = $this->pay_notify_success($order_sn, $pay_amount); if ($data['code'] == 200) { exit('OK'); } else { exit('FAIL'); } } } } public function payh5alipay($order_sn='', $money='', $title='订单支付'){ require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/AopClient.php'; require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/request/AlipayTradeWapPayRequest.php'; $config = model('admin/Config')->get_system_config(); $prv=$config['merchant_private_key']; $pov=$config['alipay_public_key']; //vendor('alipay.aop.AopSdk.AopClient'); //include_once ROOT_PATH . '/extend/alipay/aop/AopClient.php'; $aop = new \AopClient(); $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; $aop->appId = $config['ali_appid']; $aop->rsaPrivateKey = $prv; $aop->format = "json"; $aop->charset = "UTF-8"; $aop->signType = "RSA2"; $aop->alipayrsaPublicKey = $pov; $aop->apiVersion = '1.0'; //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay $request = new \AlipayTradeWapPayRequest(); // 异步通知地址 $notify_url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/api/pay_notify/ali_pay_notify'; //error_log(json_encode($notify_url), 3, 'pn.log'); $quit_url= $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/'; // 订单标题 $subject = $title; // 订单详情 $body = $title; // 订单号,示例代码使用时间值作为唯一的订单ID号 $out_trade_no = $order_sn; $total = floatval($money); //SDK已经封装掉了公共参数,这里只需要传入业务参数 $bizcontent = "{\"body\":\"".$body."\"," . "\"subject\": \"".$subject."\"," . "\"quit_url\": \"".$quit_url."\"," . "\"out_trade_no\": \"".$out_trade_no."\"," . "\"timeout_express\": \"600m\"," . "\"total_amount\": \"".$total."\"," . "\"product_code\":\"QUICK_WAP_WAY\"" . "}"; $request->setNotifyUrl($notify_url); $request->setBizContent($bizcontent); //这里和普通的接口调用不同,使用的是sdkExecute $response = $aop->pageExecute($request); // $data = '
'.$response.'
'; // return ['code' => 200, 'msg' => '成功', 'data' => $data]; // 注意:这里不需要使用htmlspecialchars进行转义,直接返回即可 echo '
'.$response.'
'; exit; } //支付宝支付 private function alipayHand($order_sn, $pay_amount) { require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/AopClient.php'; $config = model('admin/Config')->get_system_config(); $aop = new \AopClient(); $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; $aop->appId = $config['ali_appid']; $aop->alipayrsaPublicKey = $config['alipay_public_key']; $aop->rsaPrivateKey = $config['merchant_private_key']; $aop->format = "json"; $aop->charset = "UTF-8"; $aop->signType = "RSA2"; //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/request/AlipayTradeAppPayRequest.php'; ///app/Packages/alipay/aop/request $request = new \AlipayTradeAppPayRequest(); //SDK已经封装掉了公共参数,这里只需要传入业务参数 $arr['body'] = "购买商品"; $arr['subject'] = "购买商品"; $arr['out_trade_no'] = $order_sn; $arr['timeout_express'] = "30m"; $arr['total_amount'] = $pay_amount; $arr['product_code'] = "QUICK_MSECURITY_PAY"; $bizcontent = json_encode($arr, JSON_UNESCAPED_UNICODE); // $request->setNotifyUrl("http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/ali_pay_notify"); $request->setNotifyUrl("http://119.45.115.72:621/api/pay_notify/ali_pay_notify"); $request->setBizContent($bizcontent); //这里和普通的接口调用不同,使用的是sdkExecute $response = $aop->sdkExecute($request); return ['code' => 201, 'msg' => '', 'data' => $response]; } //微信支付 private function wxpayHand($order_sn, $pay_amount) { $config = model('admin/Config')->get_system_config(); require_once Env::get('root_path') . 'extend/wxPay/WxPay.php'; $WxPay = new \WxPay($config['wx_appid'], $config['wx_mch_id'], $config['wx_key']); $params['body'] = '购买商品'; //商品描述 $params['out_trade_no'] = $order_sn; //自定义的订单号 $params['total_fee'] = $pay_amount * 100; //订单金额 只能为整数 单位为分 $params['trade_type'] = 'APP'; //交易类型 JSAPI | NATIVE | APP | WAP $params['attach'] = '123'; //附加参数 // $params['notify_url'] = "http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/wx_pay_notify"; $params['notify_url'] = "http://119.45.115.72:621/api/pay_notify/wx_pay_notify"; $result = $WxPay->unifiedOrder($params); // dump($result);die; if ($result['prepay_id']) { $data = $WxPay->getOrder($result['prepay_id']); return ['code' => 200, 'msg' => '请求成功', 'data' => $data]; } else { return ['code' => 201, 'msg' => '请求失败', 'data' => null]; } } //支付宝回调 public function wxPayNotify($xmlData) { require_once Env::get('root_path') . 'extend/wxPay/WxPay.php'; $config = model('admin/Config')->get_system_config(); $WxPay = new \WxPay($config['wx_appid'], $config['wx_mch_id'], $config['wx_key']); //接收微信返回的数据数据,返回的xml格式 // $xmlData = file_get_contents('php://input'); $data = $WxPay->xml_to_data($xmlData); $sign = $data['sign']; unset($data['sign']); if ($sign == $WxPay->MakeSign($data)) { //签名验证成功后,判断返回微信返回的 if ($data['result_code'] == 'SUCCESS') { //处理交易完成或者支付成功的通知 $order_sn = $data['out_trade_no']; $pay_amount = $data['total_fee'] * 0.01; $data = $this->pay_notify_success($order_sn, $pay_amount); if ($data['code'] == 200) { exit('SUCCESS'); } else { exit('FAIL'); } } else { exit('FAIL'); } } else { exit('FAIL'); } } //支付宝异步回调 public function ali_pay_notify($data) { require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/AopClient.php'; $aop = new \AopClient(); $config = model('admin/Config')->get_system_config(); $aop->alipayrsaPublicKey = $config['alipay_public_key']; if ($data['app_id'] == $config['ali_appid'] && $data['sign_type'] == 'RSA2') { //处理业务,并从$_POST中提取需要的参数内容 if ($data['trade_status'] == 'TRADE_SUCCESS') { //处理交易完成或者支付成功的通知 $order_sn = $data['out_trade_no']; $pay_amount = $data['total_amount']; $data = $this->pay_notify_success($order_sn, $pay_amount); if ($data['code'] == 200) { exit('SUCCESS'); } else { exit('FAIL'); } } else { exit('FAIL'); } } else { exit('FAIL'); } } //支付回调验证成功 public function pay_notify_success($order_sn, $pay_amount) { $redis = connectionRedis(); $key_name = "api:user_recharge:pay_notify_success:order_sn".$order_sn; $redis_order_sn = redis_lock_exits($key_name,1,5); if($redis_order_sn){ $map = []; $map[] = ['order_sn', '=', $order_sn]; $order_info = Db::name('user_recharge')->where($map)->find(); if (empty($order_info)) { return ['code' => 201, 'msg' => '订单不存在', 'data' => null]; } if ($order_info['pay_status'] != 1) { return ['code' => 201, 'msg' => '订单已支付', 'data' => null]; } if (bcmul($order_info['money'], 100, 2) != bcmul($pay_amount, 100, 2)) { return ['code' => 201, 'msg' => '充值金额异常', 'data' => null]; } Db::startTrans(); try { //更改订单状态 $data = []; $data['pay_status'] = 2; $data['pay_time'] = time(); Db::name('user_recharge')->where('rid', $order_info['rid'])->update($data); if($order_info['order_type'] == 1){ //增加用户余额及充值记录 $result = model('admin/User')->change_user_money_by_uid($order_info['uid'], $order_info['integral'], 2, 9, "用户充值:" . $order_info['order_sn'], $order_info['uid'], $order_info['rid']); if($result['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => '充值金额异常', 'data' => null]; } //会员邀请收益 model('api/Vip')->vip_invite_earnings($order_info['uid'], $order_info['money'], $order_info['integral']); }elseif($order_info['order_type'] == 4) { $result = model('admin/User')->change_user_money_by_uid($order_info['uid'], $order_info['integral'], 2, 44, "用户购买爵位:" . $order_info['order_sn'], $order_info['uid'], $order_info['rid']); if($result['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => '充值金额异常', 'data' => null]; } $type_params = json_decode($order_info['type_params'], true); $result = model('api/Nobility')->user_pay_nobility_value($order_info['uid'], $type_params); if($result['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => '充值金额异常', 'data' => null]; } } // 提交事务 Db::commit(); return ['code' => 200, 'msg' => "成功", 'data' => null]; } catch (\Exception $e) { dump($e); // 回滚事务 Db::rollback(); return ['code' => 201, 'msg' => "失败5", 'data' => null]; } } return ['code' => 200, 'msg' => 'success', 'data' => null]; } //生成充值唯一单号 // private function create_recharge_order_sn() // { // $order_sn = 'CZ' . date('YmdHis') . mt_rand(10000, 99999); // $map = []; // $map[] = ['order_sn', '=', $order_sn]; // $reslut = db::name('user_recharge')->where($map)->find(); // if (empty($reslut)) { // return $order_sn; // } else { // $this->create_recharge_order_sn(); // } // } private function create_recharge_order_sn($type) { if($type == 1){ $order_type = 'CZ'; }else if($type == 2){ $order_type = 'HY'; }elseif($type == 4){ $order_type = 'JW'; }else { $order_type = 'JC'; } $order_sn = $order_type . date('YmdHis') . mt_rand(10000, 99999); $map = []; $map[] = ['order_sn', '=', $order_sn]; $reslut = db::name('user_recharge')->where($map)->find(); if (empty($reslut)) { return $order_sn; } else { return $this->create_recharge_order_sn($type); } } //购买会员 public function pay_nobility_order($uid, $lid, $pay_type) { $user_info = db::name('user')->find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } $pay_money = 0; $give_integral = 0; if (!in_array($pay_type, [1, 2, 21])) { return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null]; } // if ($pay_type == 21) { // return ['code' => 201, 'msg' => '系统维护中', 'data' => null]; // } if($pay_type==2){ $app_ys_wx_recharge = get_system_config('app_ys_wx_recharge'); if($app_ys_wx_recharge != 1){ return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null]; } } if($pay_type==1){ $app_ys_zfb_recharge = get_system_config('app_ys_zfb_recharge'); if($app_ys_zfb_recharge != 1){ return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null]; } } if ($pay_type == 21) { $zfbh5_huifu_recharge = get_system_config('zfbh5_huifu_recharge'); if($zfbh5_huifu_recharge != 1){ return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null]; } } $type_params = []; if(!empty($lid)){ if($user_info['nobility_id'] > $lid) { return ['code' => 201, 'msg' => '不能购买低等级会员', 'data' => null]; } $map = []; $map[] = ['lid', '=', $lid]; $nobility_info = db::name('nobility')->where($map)->find(); if(empty($nobility_info)){ return ['code' => 201, 'msg' => '购买爵位等级不存在', 'data' => null]; } if($user_info['nobility_id'] == $lid) { $pay_money = $nobility_info['renew_price']; $give_integral = $nobility_info['renew_coin']; $is_renew = 1; } else { $pay_money = $nobility_info['pay_price']; $give_integral = $nobility_info['pay_coin']; $is_renew = 2; } $type_params['pay_money'] = $pay_money; $type_params['pay_coin'] = $give_integral; $type_params['day_num'] = $nobility_info['day_num']; $type_params['is_renew'] = $is_renew; $type_params['lid'] = $lid; }else{ return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null]; } $order_sn = $this->create_recharge_order_sn(4); // $pay_money = 0.01; $data = []; $data['order_sn'] = $order_sn; $data['order_type'] = 4; $data['money'] = $pay_money; $data['integral'] = $give_integral; $data['pay_type'] = $pay_type; $data['uid'] = $uid; $data['pay_status'] = 1; $data['pay_time'] = 0; $data['remarke'] = ''; $data['add_time'] = time(); $data['update_time'] = time(); $data['type_params'] = json_encode($type_params); $data['type_id'] = $lid; $data['carry_money'] = $pay_money; $data['is_carray_finish'] = 2; $status = Db::name('user_recharge')->insert($data); $data = []; if ($status) { // return $this->pay_notify_success($order_sn, $pay_money); if ($pay_type == 1) { // $data = $this->threePayFromPost($order_sn, $pay_money, 922); $data = $this->alipayHand($order_sn, $pay_money); } elseif($pay_type == 21){ // $data = model('api/AdaPay')->create_order($order_sn, $pay_money, $uid); // if($data['code'] != 200){ // return ['code' => 201, 'msg' => '支付失败', 'data' => null]; // } // $result = $data['result']; // if(isset($result['status']) && ($result['status'] == "succeeded")){ // $payment_id = $result['id']; // $map = []; // $map[] = ['order_sn', '=', $order_sn]; // $order_info = Db::name('user_recharge')->where($map)->update(['payment_id'=>$payment_id]); // } $data = model('HuiFu1')->ali_h5($order_sn, $pay_money); if(!empty($data['data']['qr_code'])){ return ['code' => 200, 'msg' => '请求成功', 'data' => ['pay_info'=>'alipays://platformapi/startapp?saId=10000007&qrcode='.$data['data']['qr_code']]]; // return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']]; }else{ return ['code' => 201, 'msg' => '支付失败', 'data' => null]; } } else { // $data = $this->threePayFromPost($order_sn, $pay_money, 921); $data = $this->wxpayHand($order_sn, $pay_money); } } return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']]; } public function ada_ali_pay_notify($data, $sign) { // $data_str = json_encode($data,JSON_UNESCAPED_UNICODE); // $data = array ( // 'created_time' => '1721980908', // 'data' => '{"app_id":"app_260e8610-8ee2-498a-8fec-66fa866bb072","business_mode":"00","created_time":"20240726160148","description":"description","end_time":"20240726160351","expend":{"buyer_logon_id":"187****3623","cashPayAmt":"0.10","sub_open_id":"2088812171930646"},"fee_amt":"0.00","id":"002212024072616014810662820123835744256","order_no":"1721980920","out_trans_id":"2024072622001430641404087500","party_order_id":"02212407265770824408339","pay_amt":"0.10","pay_channel":"alipay","real_amt":"0.10","share_eq":"Y","status":"succeeded","trans_response_add_info":"{\\"fund_bill_list\\":[{\\"amount\\":\\"0.10\\",\\"fund_channel\\":\\"ALIPAYACCOUNT\\"}]}"}', // 'prod_mode' => 'true', // 'sign' => 'rvOfQUFTJf72dhYqQjplF9p7+jMvGYFfThJ/miFwOT2ATYc9h8Mexr8wh2ED2eetVTAeo7NLgpa+z3j0wgL8uLvC3DCUYTegZ5039nag58DVIXVEtpPrke16vlfDk7psA9xbau4BbXRVrTl9POrnhQqd+cq87hnsvj3wxd+c7o8=', // 'id' => '002210662820643004702720', // 'type' => 'payment.succeeded', // 'app_id' => 'app_260e8610-8ee2-498a-8fec-66fa866bb072', // 'object' => 'payment', // ); $post_data = $data; $data_str = json_encode($data,JSON_UNESCAPED_UNICODE); $result = model('api/AdaPay')->verify_sign($data_str, $sign); if($result['code'] != 200) { exit('FAIL'); } if($post_data['status'] == 'succeeded') { $order_sn = $post_data['order_no']; $pay_amount = $post_data['pay_amt']; $data = $this->pay_notify_success($order_sn, $pay_amount); if ($data['code'] == 200) { exit('SUCCESS'); } else { exit('FAIL'); } } exit('FAIL'); } public function hui_fu_pay_notify($data) { if($data['resp_code'] == '00000000') { $resp_data = $data['resp_data']; $resp_data_arr = json_decode($resp_data, true); $huifu_id = $resp_data_arr['huifu_id']; $sign = $data['sign']; $verify_sign = model('HuiFu1')->wx_verify_sign($resp_data, $sign, $huifu_id); if(!$verify_sign) { return ''; } if($resp_data_arr['resp_code'] == '00000000' && $resp_data_arr['trans_stat'] == 'S') { $pay_amount = bcmul($resp_data_arr['trans_amt'], 1, 2); $order_sn = $resp_data_arr['mer_ord_id']; $result = $this->pay_notify_success($order_sn, $pay_amount); if($result['code'] == 200) { exit("RECV_ORD_ID_" . $resp_data_arr['out_trans_id']) ; } } } } }