'请求参数有误(缺少或者格式有误)', '40002'=>'尚未登录/回话超时', '40500'=>'处理扫码付错误', '40510'=>'不支持的通道', '40511'=>'通道已失效', '40513'=>'商户不合法', '40520'=>'订单不存在', '40521'=>'订单已存在', '50001'=>'未授权', '50002'=>'签名错误', ]; /** * 多乐宝支付宝支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfo($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号 $params = [ 'appid' => '9d5e3cb9a4946cf28a42b99f4f8bf978', 'method' => 'payment.wxjsapp', 'merchant' => '220951176399985946', 'body' => '购买商品', 'external_order_no' => $out_trade_no1, // 我们自己的订单号 'total_amount' => $total_amount, // 'notify_url'=>'http://api.meikangjw.com/api/aliResult' 'notify_url' => 'http://zy.suncorex.com:2080/api/aliResultDLB' ]; $sign = thirdPayGetSign($params, '897d9ea909093173b24dd89c772181e4'); $params['sign'] = $sign; $res = _curlrequest('http://openpay.duolaibei.com/api/gateway', $params, 'post'); $res = json_decode($res); if ($res && isset($res->code) && $res->code == 200) { $out_trade_no = $res->content->order_no; $this->setPaymentOrder(compact('body', 'out_trade_no', 'out_trade_no1', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 5); // return api_succ_return(['msg'=>'请求成功', 'data'=>['thirdpaydlbalipay'=>['url'=>$res->content->url]]]); return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpaydlbwx' => ['url' => $res->content->url, 'jsappid' => $res->content->JSAPPID]]]); } else { return api_error_return('获取失败'); } } /** * 多乐宝微信支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getWxPayInfo($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号 $params = [ 'appid' => '9d5e3cb9a4946cf28a42b99f4f8bf978', 'method' => 'payment.wxjsapp', 'merchant' => '220951176399985946', 'body' => '购买商品', 'external_order_no' => $out_trade_no1, // 我们自己的订单号 'total_amount' => $total_amount, // 'notify_url'=>'http://api.meikangjw.com/api/aliResult' 'notify_url' => 'http://zy.suncorex.com:2080/api/wechatResultDLB' ]; $sign = thirdPayGetSign($params, '897d9ea909093173b24dd89c772181e4'); $params['sign'] = $sign; // return $params; $res = _curlrequest('http://openpay.duolaibei.com/api/gateway', $params, 'post'); // sr_log(sr_getcurtime(time()).$res); // {"code":200,"msg":"success","content":{"order_no":"DLB1649853909589099089998901OP","external_order_no":"12365847092204130845091649853909","total_amount":11970,"body":"\u8d2d\u4e70\u5546\u54c1","trans_type":"AL_JSAPP","JSAPPID":"2021002148663267","url":"alipays:\/\/platformapi\/startapp?appId=2021002148663267&page=pages\/open-pay\/open-pay&query=order_no%3DDLB1649853909589099089998901OP","sign":"FA06F884C143DA40E505950918D4AD45"}} $res = json_decode($res); if ($res && isset($res->code) && $res->code == 200) { $out_trade_no = $res->content->order_no; $this->setPaymentOrder(compact('body', 'out_trade_no', 'out_trade_no1', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 5); // return api_succ_return(['msg'=>'请求成功', 'data'=>['thirdpaydlbalipay'=>['url'=>$res->content->url]]]); return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpaydlbwx' => ['url' => $res->content->url, 'jsappid' => $res->content->JSAPPID]]]); } else { return api_error_return('获取失败'); } } /** * 畅联微信支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getWxPayInfoCL($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $out_trade_no = 'CL' . rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号 $success_url = getWebUrl() . '/api/thirdPayClSuccess'; $error_url = getWebUrl() . '/api/thirdPayClError'; $params = [ 'appid' => '1059174', 'pay_type' => 'partnerJs', 'amount' => sprintf("%.2f", $total_amount), 'callback_url' => getWebUrl() . '/api/wechatResultCL', 'success_url' => $success_url, 'error_url' => $error_url, 'extend' => '{"body":"购买商品"}', 'out_trade_no' => $out_trade_no ]; // sr_log(json_encode($params)); $sign = thirdPayGetSignCL('XMLfjHMPOGexsSaadIWSVCNG0XJBClZZ', $params); $params['sign'] = $sign; // sr_log(json_encode($params)); // return $params; $res = _curlrequest('https://api.payunk.com/index/unifiedorder?format=json', $params, 'post'); sr_log(sr_getcurtime(time()) . $res); $res = json_decode($res); if ($res && isset($res->code) && $res->code == 200) { $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 7); return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpayclwx' => ['url' => $res->url, 'success_url' => $success_url, 'error_url' => $error_url]]]); } else { return api_error_return('获取失败'); } } /** * 畅联支付宝支付 type aban(A版本) h5ban(h5版本) dban(D版本) * @param $uid * @param $params * @param $type * @return \think\Response * @throws Exception */ public function getAliPayInfoCL($uid, $params, $type) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); // 这是测试 线要干掉 // $total_amount = floatval('0.'.mt_rand(1, 3).mt_rand(1, 9)); // $total_amount = 0.01; $out_trade_no = 'CL' . rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号 $success_url = getWebUrl() . '/api/thirdPayClSuccess'; $error_url = getWebUrl() . '/api/thirdPayClError'; $type_arr = [ 'aban' => 'alipayApp', 'h5ban' => 'adapayH5', 'dban' => 'alipayPrecreate' ]; $params = [ 'appid' => '1059174', 'pay_type' => $type_arr[$type], 'amount' => sprintf("%.2f", $total_amount), 'callback_url' => getWebUrl() . '/api/AliResultCL', 'success_url' => $success_url, 'error_url' => $error_url, 'extend' => '{"body":"购买商品","subject":"购买商品"}', 'out_trade_no' => $out_trade_no ]; // sr_log(json_encode($params)); $sign = thirdPayGetSignCL('XMLfjHMPOGexsSaadIWSVCNG0XJBClZZ', $params); $params['sign'] = $sign; // sr_log(json_encode($params)); // return $params; $res = _curlrequest('https://api2.payunk.com/index/unifiedorder?format=json', $params, 'post'); // sr_log(sr_getcurtime(time()).$res); $res = json_decode($res); if ($res && isset($res->code) && $res->code == 200) { $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), ($type == 'aban' ? 10 : 8)); return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpayclali' => ['url' => $res->url, 'success_url' => $success_url, 'error_url' => $error_url]]]); } else { return api_error_return('获取失败'); } } /** * mo宝 富有 银联支付 * @param $uid * @param $paramscon * @return \think\Response * @throws Exception */ public function getBankPayInfoFY($uid, $paramscon) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $paramscon); // 商户号 $mchnt_cd = env('api.PAY_FUYOU_MCHNT_id'); $time = time(); $time_end = time() + 2 * 60 * 60; $order_date = sr_getcurtime($time, 'Ymd'); $order_timestart = sr_getcurtime($time, 'YmdHis'); $order_timeend = sr_getcurtime($time_end, 'YmdHis'); $order_id = $paramscon['order_id']; $out_trade_no = 'FYYL' . $order_id; $mess_arr = ['mchnt_cd' => $mchnt_cd, 'order_date' => $order_date, 'order_id' => $paramscon['order_id'], 'ver' => '1.0.0']; // sr_log('message_json'.json_encode($mess_arr)); $params = ['mchnt_cd' => $mchnt_cd, 'message' => RSA_openssl(json_encode($mess_arr))]; // 测试 // $url = 'https://aggapp-test.fuioupay.com/token.fuiou'; // 正式 $url = 'https://aggapp.fuioupay.com/token.fuiou'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $headers = ['Content-type: application/json']; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // POST数据 curl_setopt($ch, CURLOPT_POST, 1); // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // 把post的变量加上 $data = json_encode($params); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); // sr_log('ccc'.$output); $rsares = json_decode($output); $res_decode = json_decode(RSA_openssl($rsares->message, 'decode')); sr_log('ccc' . json_encode($res_decode)); if (isset($res_decode->order_date) && isset($res_decode->order_token) && isset($res_decode->mchnt_cd) && isset($res_decode->order_id)) { if ($res_decode->mchnt_cd == $mchnt_cd && $res_decode->order_id == $order_id) { $bank_params = [ 'mchnt_cd' => $mchnt_cd, 'order_date' => $order_date, 'order_amt' => bcmul($total_amount, 100, 0), 'order_id' => $order_id, 'page_notifyurl' => ($paramscon['app_sources'] == 'ios' ? getWebUrl() . '/api/thirdPayClSuccess' : AESjiami(getWebUrl() . '/api/thirdPayClSuccess')), 'back_notifyurl' => ($paramscon['app_sources'] == 'ios' ? getWebUrl() . '/api/BankResultFY' : AESjiami(getWebUrl() . '/api/BankResultFY')), 'order_timestart' => $order_timestart, 'order_timeend' => $order_timeend, 'order_token' => $res_decode->order_token ]; $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 9); return api_succ_return(['msg' => '成功', 'data' => ['thirdpayflyl' => $bank_params]]); } else { return api_error_return('获取失败,订单校验失败1'); } } else { return api_error_return('获取失败,订单校验失败'); } return api_error_return('获取失败'); } /** * 易票联 支付宝支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getZfbPayInfoYPL($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $order_id = $params['order_id']; $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000); $success_url = getWebUrl() . '/api/thirdPayClSuccess'; $error_url = getWebUrl() . '/api/thirdPayClError'; $notify_url = getWebUrl() . '/api/ZfbResultYPL'; $orderInfo = array(); $orderInfo['Id'] = 'id34535'; $orderInfo['businessType'] = '130001'; $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1)); $params = [ 'areaInfo' => '440106', 'attachData' => 'attachData', 'clientIp' => request()->ip(), 'customerCode' => '562012003860535', 'nonceStr' => nonce_str(32), 'notifyUrl' => $notify_url, 'orderInfo' => $orderInfo, 'outTradeNo' => $out_trade_no, 'payAmount' => bcmul($total_amount, 100, 0), 'payCurrency' => 'CNY', 'payMethod' => '7', 'redirectUrl' => $success_url, 'transactionStartTime' => date('YmdHis'), 'version' => '3.0' ]; sr_log(json_encode($params)); // 测试 // $url = 'http://test-efps.epaylinks.cn'; // 正式 $url = 'https://efps.epaylinks.cn'; $url = $url . '/api/txs/pay/NativePayment'; $sign = $this->YPLsign(json_encode($params)); $headers = [ // 'Content-type: application/json', 'x-efps-sign-no' => '562012003860535001', 'x-efps-sign-type' => 'SHA256withRSA', 'x-efps-sign' => $sign, 'x-efps-timestamp' => date('YmdHis') ]; sr_log(json_encode('header' . json_encode($headers))); // J+08ZMVCkZnMq0roi3JikP//ODGsy9UvYBM09b921RvU0/3Z+4opOwAFQGPBLrKRGhkZzVhHRJwVDZHA9Iu/wWX13SJyowRYkr8zVsYivNQhYKyt3uPScdN/BVfLM3d5OuA9o2ypIqVuoinorYDsrqXixyYg7LEA4pWTDZc9dtuSRWFF+DFvLTW4UODyiwhBCq7bFaa+MOVmWuiahZMM79MhKxiTqsfFQLptsnlc2crlYuok2Bp2TAbEDM7FZhlLIGiidux0kaLhC3dK31tRc6Y72NlukXJc3sN4HVLqj0GAiw+9jzmGf0NwhvxdHvBC6/7uOp2ShCMxSXUA/qPbLmA7Vh/Zv0njHbxJ0j3oylrhjCjUKGPTKf//GD/vgnVQz2m3KXW6+60PBfWRYwQYkSPFRHj2lRALBYe97q4w0kWa9xO/2yRrIW2lNBqt7ZKSmSstsA+NgiOU4u/LCBmIoxMqk9HzygfDPLhQ9oimOuM/7d//qjP0z6mPD4SbhdVKjfgsp9yqN7h9jR3BJJxDGRAtzJJpDA6/YIcTbkDnJIvHwIx4Fkcf22tBYW436W7f +0GeMLxBp5mAr8qlDJt0R3GoPD4hZ5Omh/FxYhOjN9RKG8QcqSykZSQgYgVAKsGeFWVeXes2XNo2AB1F7MlGuZSypOTv73BL5iE75xJVjRupk6qplmOo2YHLKs8USDSX3Y+QprbAC8irxQ5QtK4ayGbLZ8BDHuKnGLLA1/ID++2ccYJsnfA+9cqvSTm8lo19W1btBl9iZQC8Wfv94rfDsIAe2pc3Gd+LJv47i1mwzK03SQ5c6W8LBxgtStinz/f8Rm5oVn6hTgoRfV93F8ZGRVj5K+KYva5qIjBSyweYToPoXCirUO0UdA96PmU7+oVVOVu4pDcqBJjuSxPXIzRLXbSQUlFHecKjedx2DuOlHPdVMhn2XRjpdd+Ka70Grbw0dro76EvaBzHC2x/rN7g8nIe7ReG4LS2ya07bIXrbHyk6b45XfrneBGHnKDpIX6ymlDKZ2NAWyfXkBEPhiQrsT3AVGrokFjMTRVqubXqRW29Q8if2C5MYduen34s3QtmVHaVUZ24N6cX5FIvCwZYIyBvpFrTCfQZztRz3QngjhclbngGGyBv040WFfQ/sqzkWgdO8XP7cIUWlKmD0xANVq9dQqQiwwcvYpWFzMTpQcw9daGYWltwfzKfRveVnXHyfxaq6XVeHlZCboTDv4Fg5/nVW+s4JCmTXNPedU53ZYcDkrrZcHbygFXgPPOM8KMlowq8KnA9lXUYunHATpa2Q9vKnTED8Ro9gn6IGFpGRdZIeuYOJ+vKMA9sy55AIQiJVUMit7iw2M0ZehPwm4k5Dpi6RMzgC/5+OZc1u+Rt13Borvd3/7EuyqaNwhUkITp7Kl0dv75PQkK0Btcsg+PLVs+2h+GadNurWhl3Bvo6y++5HbkcEfymSFV/phDaAZBTYQFyzjAJhwJizMUBp1HFOetOiLEZSs4iMPj/gwps0BSwqCCRFZXJj3ifLo+fi/bE3rU+/nHcTBo9Dhzw/EVE2KLF1QbZw3fGLnhHqCK+PyOv4i7NwEQKqsA== $response = $this->http_post_json($url, json_encode($params), $sign); sr_log($response); if ($response && $response[0] == 200) { $re_data = json_decode($response[1], true); if ($re_data['returnCode'] == '0000') { $payurl = $re_data['codeUrl']; $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 12); return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPL' => ['pay_url' => $payurl]]]); // return api_succ_return(['msg'=>'成功', 'data'=>['thirdpay'=>['url'=>$payurl]]]); // } } else { return api_error_return('获取失败,请联系客服'); } return api_error_return('获取失败,请联系客服'); } /** * 易票联云闪付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getYsfPayInfoYPL($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); // 商户号 $mchnt_cd = env('api.PAY_FUYOU_MCHNT_id'); $order_id = $params['order_id']; $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000); $success_url = getWebUrl() . '/api/thirdPayClSuccess'; $error_url = getWebUrl() . '/api/thirdPayClError'; $notify_url = getWebUrl() . '/api/ZfbResultYPL'; $orderInfo = array(); $orderInfo['Id'] = 'id34535'; $orderInfo['businessType'] = '130001'; $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1)); // $order_timestart = sr_getcurtime($time, 'YmdHis'); $params = [ 'areaInfo' => '440106', 'attachData' => 'attachData', 'clientIp' => request()->ip(), 'customerCode' => '562012003860535', 'nonceStr' => nonce_str(32), 'notifyUrl' => $notify_url, 'orderInfo' => $orderInfo, 'outTradeNo' => $out_trade_no, 'payAmount' => bcmul($total_amount, 100, 0), 'payCurrency' => 'CNY', 'redirectUrl' => $success_url, 'transactionStartTime' => date('YmdHis'), 'version' => '3.0' ]; sr_log('ypl' . json_encode($params)); // 测试 // $url = 'http://test-efps.epaylinks.cn'; // 正式 $url = 'https://efps.epaylinks.cn'; $url = $url . '/api/txs/pay/UnionAppPayment'; sr_log('yplurl:' . $url); $sign = $this->YPLsign(json_encode($params)); $headers = [ // 'Content-type: application/json', 'x-efps-sign-no' => '562012003860535001', 'x-efps-sign-type' => 'SHA256withRSA', 'x-efps-sign' => $sign, 'x-efps-timestamp' => date('YmdHis') ]; sr_log('yplheader' . json_encode($headers)); $response = $this->http_post_json($url, json_encode($params), $sign); sr_log('yplresponse' . json_encode($response)); if ($response && $response[0] == 200) { $re_data = json_decode($response[1], true); if ($re_data['returnCode'] == '0000') { $tn = $re_data['tn']; $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 13); return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPLYsf' => ['tn' => $tn]]]); // } } else { return api_error_return('获取失败,请联系客服'); } return api_error_return('获取失败,请联系客服'); } /** * 汇付支付宝支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getHfPayInfoHF($uid, $params) { // 加载基础 adapay 基础类 // SDK 初始化文件加载 include_once "../extend/thirdpay/AdapaySdk/init.php"; // 在文件中设置 DEBUG 为 true 时, 则可以打印日志到指定的日志目录下 LOG_DIR include_once "../extend/thirdpay/config.php"; list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); // 这是测试 线要干掉 if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { // 这是测试 线要干掉 $total_amount = floatval('1.' . mt_rand(1, 3) . mt_rand(1, 9)); } $time_end = time() + 2 * 60 * 60; $order_timeend = sr_getcurtime($time_end, 'YmdHis'); $order_id = $params['order_id']; $out_trade_no = 'HFPAY' . $order_id . mt_rand(1, 10000); # 初始化支付类 $payment = new \AdaPaySdk\Payment(); # 支付设置 $payment_params = array( "app_id" => "app_3906a188-adf7-4776-a126-fd1996b178d3", "order_no" => $out_trade_no, "pay_channel" => "alipay", "time_expire" => $order_timeend, "pay_amt" => strval(intval($total_amount)) . '.00', "goods_title" => "日用生活用品", "goods_desc" => "多宝购买商品", "description" => "购买商品", "notify_url" => getWebUrl() . '/api/ZfbResultHF' ); sr_log('汇付支付请求参数:' . json_encode($payment_params)); # 发起支付 $payment->create($payment_params); # 对支付结果进行处理 if ($payment->isError()) { //失败处理 $response = $payment->result; sr_log('hfresponseerror' . json_encode($response)); return api_error_return('获取失败,请联系客服'); } else { //成功处理 $response = $payment->result; $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 14); $bank_params = [ 'url' => $response['expend']['pay_info'] ]; return api_succ_return(['msg' => '成功', 'data' => ['thirdpayhf' => $bank_params]]); } return api_error_return('获取失败,请联系客服'); } /** * 易票联统一支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getYsfPayInfoTY($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); // 商户号 $order_id = $params['order_id']; $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000); $success_url = getWebUrl() . '/api/thirdPayClSuccess'; $error_url = getWebUrl() . '/api/thirdPayClError'; $notify_url = getWebUrl() . '/api/ZfbResultYPL'; // 商品订单信息 $orderInfo = array(); $orderInfo['Id'] = 'id34535'; $orderInfo['businessType'] = '130001'; $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1)); $params = [ 'areaInfo' => '440106', 'attachData' => 'attachData', 'clientIp' => request()->ip(), 'customerCode' => '562012003860535', 'nonceStr' => nonce_str(32), 'notifyUrl' => $notify_url, 'orderInfo' => $orderInfo, 'outTradeNo' => $out_trade_no, 'payAmount' => bcmul($total_amount, 100, 0), 'payCurrency' => 'CNY', 'redirectUrl' => $success_url, 'transactionStartTime' => date('YmdHis'), 'version' => '3.0' ]; sr_log('ypl' . json_encode($params)); // 测试 // $url = 'http://test-efps.epaylinks.cn'; // 正式 $url = 'https://efps.epaylinks.cn'; $url = $url . '/api/txs/pay/UnifiedPayment'; sr_log('yplurl:' . $url); $sign = '333'; $headers = [ 'x-efps-sign-no' => '562012003860535001', 'x-efps-sign-type' => 'SHA256withRSA', 'x-efps-sign' => $sign, 'x-efps-timestamp' => date('YmdHis') ]; sr_log('yplheader' . json_encode($headers)); $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 13); return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPLYsf' => ['tn' => $out_trade_no]]]); } /** * 易票联进件申请 * @param $uid * @param $params * @return \think\Response */ public function getYsfPayJJSubmit($uid, $params) { $time = time(); $time_end = time() + 2 * 60 * 60; $order_date = sr_getcurtime($time, 'Ymd'); $order_timestart = sr_getcurtime($time, 'YmdHis'); $order_timeend = sr_getcurtime($time_end, 'YmdHis'); $success_url = 'https://api.meikangjw.com/api/yplApplyResult'; $error_url = getWebUrl() . '/api/thirdPayClError'; $notify_url = getWebUrl() . '/api/ZfbResultYPL'; $paper = array(); //------------------------------------------------------- // 经营地址 $paper['businessAddress'] = '重庆市渝北区回兴街道宝圣大道209号西政国际学术交流中心1幢'; // 证件人姓名 $paper['certificateName'] = '胡明冬'; // 证件效期(截止) 无限期填写“长期” $paper['certificateTo'] = '20270104'; // 省 $paper['province'] = '500000'; // 市 $paper['city'] = '500100'; // 区 $paper['area'] = '500112'; // MCC 码 参考附件商户类别 MCC 码 $paper['mcc'] = '5399'; // 联系人姓名 $paper['contactPerson'] = '胡明冬'; // 联系人手机号码 $paper['contactPhone'] = '13330218461'; // 邮箱地址 $paper['email'] = '845313908@qq.com'; // $paper['isCc']='1'; // 证件号码 $paper['lawyerCertNo'] = '513002199602181213'; //// 证件背面 $paper['lawyerCertPhotoBack'] = 'https://api.meikangjw.com/upload/20220707/42b46e4e6b82c81b9bb3c72d1c630c80.jpg'; /// // 证件正面照 $paper['lawyerCertPhotoFront'] = 'https://api.meikangjw.com/upload/20220707/5fa0ff6cc891e545c1aa423db7613f63.jpg'; // 0:身份证;1:居住证;2:签证;3:护照;4:户口本;5:军人证;6:团员证;7:党员证;8:港澳通行证;9:台胞证;11:临时身份证;12:回乡证;13:营业执照:14:组织机构代码证;15:驾驶证;99:其他目前仅支持 0:身份证 $paper['lawyerCertType'] = '0'; // 开户银行 填写银行名称,参见附件银行 $paper['openBank'] = '中国工商银行'; // 开户行联行号 settleAccountType 为“1:对公账户”时必填,参见附件支行及联行号 查询不到 看链接查询 https://www.lianhanghao.com/ $paper['openBankCode'] = '102290010045'; // 开户支行 settleAccountType 为“1:对公账户”时必填 $paper['openSubBank'] = '中国工商银行股份有限公司上海市闵行支行'; // 客服电话 $paper['serviceTel'] = '13330218461'; // 结算账户名 ①merchantType=1、2 且 settleAccountType=1 时,需与merchantName 一致; ②merchantType=1、2 且 settleAccountType=2 时,需与lawyerName 一致; ③merchantType=3 时,需与 certificateName 一致。 $paper['settleAccount'] = '胡明冬'; // 1:个体工商户;2:企业;3:个人(小微);4:政府 事业单位;9:其他组织 $paper['merchantType'] = '3'; // 结算账户类型 1:对公账户 2:法人账户 3:授权对公 4:授权对私 merchantType=3 时必填 2。 $paper['settleAccountType'] = '2'; // 银行卡正面照 $paper['bankCardPhotoFront'] = 'https://api.meikangjw.com/upload/20220707/1d80b9edb7773c0d1313270a9b39da6c.jpeg'; // 银行卡背面照 $paper['bankCardPhotoBack'] = 'https://api.meikangjw.com/upload/20220707/aff7377fff22225bff320a51cddaa75d.jpeg'; // 结算账户号 $paper['settleAccountNo'] = '6222031001022713072'; // 提现方式 1:自动提现;2:手动提现 $paper['settleTarget'] = '2'; // 商户简称 $paper['shortName'] = 'hmd_xiaowei'; // 门店内景照 $paper['storeHallPhoto'] = 'https://api.meikangjw.com/upload/20220711/a9ed2ef249e919c8432f756bd4b29a0a.jpg'; // 门店门头照 $paper['storeHeadPhoto'] = 'https://api.meikangjw.com/upload/20220711/e3491c28c5096fc20b6c84efff3b003e.jpg'; // 门店外景照 $paper['storeShopPhoto'] = 'https://api.meikangjw.com/upload/20220711/e3491c28c5096fc20b6c84efff3b003e.jpg'; // $paper['unionShortName']='蜀盛锦蓉店铺'; // refundFeeRate 退款手续费费率 // settleCycle 结算周期 // stage 手续费费率 // stage.amountFrom 阶梯起始交易金额 // stage.feePer 单笔收费 // stage.feeRate 按比例收费 // 代付带储蓄卡 $b_withdraw = array('bankStage' => [], 'businessCode' => 'WITHDRAW', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+0', 'stage' => array(array('amountFrom' => 0, 'feePer' => 200))); // 支付宝 主扫支付 $b_alinav = array('bankStage' => [], 'businessCode' => 'ALI_NATIVE_PAY', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+1', 'stage' => array(array('amountFrom' => 0, 'feeRate' => 60))); // 支付宝生活号支付 $b_alinav1 = array('bankStage' => [], 'businessCode' => 'ALI_JSAPI_PAY', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+1', 'stage' => array(array('amountFrom' => 0, 'feeRate' => 60))); $business = array($b_withdraw, $b_alinav, $b_alinav1); $params = [ // 是否收单 1 是,0 否 'acceptOrder' => '1', // 平台商户编号 'acqSpId' => '562012003860535', // 审核回调地址 'backUrl' => $success_url, 'business' => $business, // 填写进件的小微名字 'merchantName' => '重庆闲食有趣', // 是否开户 'openAccount' => '1', 'paper' => json_encode($paper), // 更换子商户信息必传 'acqMerId' => 562227003867484 ]; sr_log('yplpaper' . json_encode($paper)); sr_log('ypl' . json_encode($params)); // 正式 $url = 'https://efps.epaylinks.cn'; // 商户进件或者补件 $url = $url . '/api/cust/SP/Merchant/apply'; sr_log('yplurl:' . $url); $sign = $this->YPLsign(json_encode($params)); $headers = [ 'x-efps-sign-no' => '562012003860535001', 'x-efps-sign-type' => 'SHA256withRSA', 'x-efps-sign' => $sign, 'x-efps-timestamp' => date('YmdHis') ]; sr_log('yplheader' . json_encode($headers)); $response = $this->http_post_json($url, json_encode($params), $sign); sr_log('yplresponse' . json_encode($response)); if ($response && $response[0] == 200) { $re_data = json_decode($response[1], true); if ($re_data['respCode'] == '0000') { return api_succ_return('成功'); } else { return api_error_return($re_data['respMsg']); } } else { return api_error_return('获取失败,请联系客服'); } return api_error_return('获取失败,请联系客服'); return api_error_return('获取失败'); } /** * http请求 * @param $url * @param $jsonStr * @param $sign * @return array */ protected function http_post_json($url, $jsonStr, $sign) { $ch = curl_init(); $headers = array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($jsonStr), 'x-efps-sign-no:' . '562012003860535001', 'x-efps-sign-type:SHA256withRSA', 'x-efps-sign:' . $sign, 'x-efps-timestamp:' . date('YmdHis'), ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 跳过检查 //curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($httpCode, $response); } /** * 签名 * @param $data * @return string */ protected function YPLsign($data) { $certs = array(); if (env("app.CUR_SYS_PARAMS") == 1) { //其中password为你的证书密码 openssl_pkcs12_read(file_get_contents('/Users/sunriseos/Documents/www/wwwroot/cert/ypl/user-rsa.pfx'), $certs, 'zy2033.'); } else { openssl_pkcs12_read(file_get_contents('/www/wwwroot/cert/ypl/user-rsa.pfx'), $certs, 'zy2033.'); //其中password为你的证书密码 } ($certs) or die('您使用的私钥格式错误,请检查RSA私钥配置'); openssl_sign($data, $sign, $certs['pkey'], OPENSSL_ALGO_SHA256); $sign = base64_encode($sign); return $sign; } /** * 费用配置 * @param int $uid * @param array $data * @param int $type * @return array */ public function _payConf(int $uid, array $data, int $type = 1) { $body = $total_amount = $remarks = ''; switch ($data['order_type']) { case 1: // 充值 $body = '充值'; $total_amount = $data['money']; break; case 2: // 实名认证 $total_amount = Db::name('user_data')->where('uid', $uid)->value('rz_money'); $body = '实名认证费用'; break; case 3: // 开通会员 $vip_money = env('app.VIP_MONEY', 38); if (!$vip_money > 0) { throw new Exception('会员配置不存在'); } $body = '开通会员'; $total_amount = $vip_money; $remarks = $data['order_id']; break; case 4: //购买商品 $order_sn = $data['order_id']; $checkingOrder = Order::checkingOrder($order_sn, 0, $uid); if (!$checkingOrder) { throw new Exception('校验订单失败'); } if ($checkingOrder['flag'] !== 200) { throw new Exception($checkingOrder['msg']); } $body = '购买商品'; $total_amount = $checkingOrder['orderPayment']; $remarks = $order_sn; //更改订单支付状态为线下支付待审核状态 if ($data['channel'] == 4 && $data['order_type'] == 4) { Order::where('order_sn', 'in', $order_sn)->save(['pay_type' => 4, 'status' => 4]); } break; case 5: //余额充值 { if (intval($data['money']) < 0) { sr_throw('金额填写错误,请填写整数'); } if (!str_is_int($data['money'])) { sr_throw('充值金额有误,请输入正整数'); } if ($data['money'] > 10000 || $data['money'] < 20) { sr_throw('请输入20到10000之间金额充值'); } if ($data['channel'] == 19) { $usdt_price = Db::name('system_config')->where('name', 'usdt_price')->where('group', 'usdt_price')->value('value'); } $charge_sn = createdRechargeOrderSn(); Db::name('recharge_order')->insertGetId([ 'recharge_sn' => $charge_sn, 'payment' => $data['money'], 'total_price' => $data['money'], 'usdt_money' => ($data['channel'] == 19 ? ceil($data['money'] / $usdt_price * 100) / 100 : 0), 'user_id' => $uid, 'pay_type' => $data['channel'], 'status' => 1, 'expires_time' => sr_getcurtime(time() + 0.5 * 3600), 'created_time' => sr_getcurtime(time()) ]); $count = Db::name('recharge_order')->where('user_id', $uid)->where('pay_type', $data['channel'])->where('status', 1)->whereTime('created_time', '-2 hours')->count('order_id'); if ($count > 20) { sr_throw('未支付订单过多请2小时后在试'); } $body = '用户充值'; $total_amount = $data['money']; $remarks = $charge_sn; } break; case 6: { $money = env('boxsetting.SERVICES_STORE_OPEN_PRICE'); $charge_sn = createdRechargeOrderSn(); Db::name('services_order')->insertGetId([ 'recharge_sn' => $charge_sn, 'payment' => $money, 'total_price' => $money, 'usdt_money' => 0, 'user_id' => $uid, 'pay_type' => $data['channel'], 'status' => 1, 'expires_time' => sr_getcurtime(time() + 0.5 * 3600), 'created_time' => sr_getcurtime(time()) ]); $count = Db::name('services_order')->where('user_id', $uid)->where('pay_type', $data['channel'])->where('status', 1)->whereTime('created_time', '-2 hours')->count('order_id'); if ($count > 20) { sr_throw('未支付订单过多请稍后在试'); } $body = '用户购买服务商服务'; $total_amount = $money; $remarks = $charge_sn; } break; } if (!$body || !$total_amount || $total_amount <= 0){ throw new Exception('配置错误'); } return [$body, $type == 1 ? $total_amount : bcmul($total_amount, 100, 2), $data['order_type'], $remarks, $data['trade_type'], $data['channel'], isset($data['voucher_img']) ? $data['voucher_img'] : '']; } /** * @param $uid * @param $params * @return \think\Response * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getPayInfoSQZ($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $nowTime = date('Y-m-d H:i:s'); $signId = isset($params['sign_id'])? $params['sign_id'] : 0; $payCode = PaymentService::make()->getPayCode($pay_way); $cacheKey = "caches:payment:{$payCode}:signid_{$signId}:"; $signInfo = UserBankSignService::make()->getCacheInfo($signId,$uid); RedisCache::set($cacheKey.'catch',['params'=> $params, 'sign'=> $signInfo,'date'=> $nowTime], 7200); if (!$signInfo) { sr_throw('参数错误'); } $order_id = ''; if ($order_type == 4) { $order_id = $params['order_id']; } if ($order_type == 5) { $order_id = $remarks; } if ($order_type == 6) { // 如果是购买服务商订单 order_id 就是 services_order 里面的order_id $order_id = $remarks; } $out_trade_no = 'SY' . $order_id . mt_rand(1, 10000); // PAYBACK_URL $pay_success_backurl = env('PAYSQZ.PAYBACK_URL'); if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { // 这是测试 线要干掉 $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9)); } $parterid = env('PAYSQZ.PARTER'); $apiData = [ 'parter' => $parterid, 'type' => 1000, 'value' => $total_amount, 'orderid' => $out_trade_no, // 'hy_auth_uid' => env('PAYSQZ.SXY_PARTER'), 'callbackurl' => $pay_success_backurl, 'payerIp' => get_client_ip(), 'userno' => $signInfo['userno'] ]; $apiUrl = 'http://pay.xindonglife.com/chargebank.aspx'; $apiData['sign'] = md5('parter=' . $parterid . '&type=' . '1000' . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY')); RedisCache::set($cacheKey.'request',['url'=>urldecode($apiUrl),'params'=> $params,'apiData'=>$apiData, 'sign'=> $signInfo,'date'=> $nowTime], 7200); $result = _curlrequest($apiUrl, $apiData, 'post'); $res = $result? json_decode($result, true) : []; RedisCache::set($cacheKey.'request',['url'=>$apiUrl,'params'=> $params,'apiData'=>$apiData, 'result'=>$result, 'sign'=> $signInfo,'date'=> $nowTime], 7200); if (isset($res->code) && $res->code == 'SUCCESS') { $insert = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => $res->orderid, 'hy_token_id' => $res->hy_token_id ]; if(!PaymentModel::insert($insert)){ sr_throw('调用处理失败'); } RedisCache::set($cacheKey.'request',['url'=>$apiUrl,'params'=> $params,'apiData'=>$apiData,'result'=>$res,'payment'=>$insert,'sign'=> $signInfo,'date'=> $nowTime], 7200); return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySYL' => ['orderid' => $res->orderid, 'mobile' => $signInfo['phone']]]]); } return api_error_return('调用失败,请确定账号无误后联系客服'); } /** * 石区长-支付宝 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfoSQZAlipay($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $order_id = ''; if ($order_type == 4) { $order_id = $params['order_id']; } if ($order_type == 5) { $order_id = $remarks; } $out_trade_no = 'SA' . $order_id . mt_rand(1, 10000); // PAYBACK_URL $pay_success_backurl = env('PAYSQZ.PAYAliBACK_URL'); if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { // 这是测试 线要干掉 $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9)); } $parterid = env('PAYSQZ.PARTER'); $params = [ 'parter' => $parterid, 'type' => 1010, 'value' => $total_amount, 'orderid' => $out_trade_no, 'callbackurl' => $pay_success_backurl, 'payerIp' => request()->ip() ]; // 提交确定支付 sr_log('确认支付支付宝:' . json_encode($params)); $params['sign'] = md5('parter=' . $parterid . '&type=' . '1010' . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY')); $url = 'http://pay.xindonglife.com/chargebank.aspx'; $insert = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => '', 'hy_token_id' => '' ]; Db::name('payment')->insert($insert); $pay_url = $url . '?' . http_build_query($params); sr_log('支付宝支付链接:' . $pay_url); return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZAlipay' => ['pay_url' => $pay_url]]]); } /** * 石区长-微信支付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfoSQZWechat($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $order_id = ''; if ($order_type == 4) { $order_id = $params['order_id']; } if ($order_type == 5) { $order_id = $remarks; } $out_trade_no = 'Sw' . $order_id . mt_rand(1, 10000); $pay_success_backurl = env('PAYSQZ.PAYWeixinBACK_URL'); if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { // 这是测试 线要干掉 $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9)); } $parterid = env('PAYSQZ.PARTER'); $type = 1004; $params = [ 'parter' => $parterid, 'type' => $type, 'value' => $total_amount, 'orderid' => $out_trade_no, 'callbackurl' => $pay_success_backurl, 'payerIp' => request()->ip() ]; // 提交确定支付 sr_log('确认支付:' . json_encode($params)); $params['sign'] = md5('parter=' . $parterid . '&type=' . $type . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY')); $url = 'http://pay.xindonglife.com/chargebank.aspx'; $insert = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => '', 'hy_token_id' => '' ]; Db::name('payment')->insert($insert); return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZ' => ['pay_url' => $url . '?' . http_build_query($params)]]]); } /** * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfoSQZBankkuai($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $order_id = ''; if ($order_type == 4) { $order_id = $params['order_id']; } if ($order_type == 5) { $order_id = $remarks; } $out_trade_no = 'SK' . $order_id . mt_rand(1, 10000); $pay_success_backurl = env('PAYSQZ.PAYKUAIJIEBACK_URL'); if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { // 这是测试 线要干掉 $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9)); } $parterid = env('PAYSQZ.SXY_PARTER'); $type = 967; $params = [ 'parter' => $parterid, 'type' => $type, 'value' => $total_amount, 'orderid' => $out_trade_no, 'callbackurl' => $pay_success_backurl, 'payerIp' => request()->ip() ]; // 提交确定支付 sr_log('确认支付:' . json_encode($params)); $params['sign'] = md5('parter=' . $parterid . '&type=' . $type . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SXY_SIGNKEY')); $url = 'http://pay.xindonglife.com/chargebank.aspx'; $insert = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => '', 'hy_token_id' => '' ]; Db::name('payment')->insert($insert); return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZ' => ['pay_url' => $url . '?' . http_build_query($params)]]]); } /** * 银盛快捷无卡 * @param $uid * @param $params * @return \think\Response * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getPayInfoYSwk($uid, $params) { if (empty($params['cer_no']) || empty($params['cer_name'] || empty($params['bank_id']) || empty($params['bank_type']) || empty($params['bank_no']) || empty($params['mobile']))) { return api_error_return("参数错误"); } if ($params['bank_type'] == 2) { if (empty($params['card_expr_time']) || empty($params['security_code'])) { return api_error_return('信用卡类型必须填写信用卡上面的三位安全码跟过期时间'); } } $bank_info = Db::name('ys_banklist')->where('id', $params['bank_id'])->find(); if (!$bank_info) { return api_error_return('参数错误'); } $buy_mobilee = $params['mobile']; list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); $interface_url = 'https://openapi.ysepay.com/gateway.do'; //正式 $order_id = ''; if ($order_type == 4) { $order_id = $params['order_id']; } if ($order_type == 5) { $order_id = $remarks; } $out_trade_no = $order_id . '_yswk' . mt_rand(1, 10000); // PAYBACK_URL $pay_success_backurl = env('PAYSQZ.PAYKUAIJIEBACK_URL'); // $total_amount = 1; if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { // 这是测试 线要干掉 $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9)); } $parterid = env('ZLYS.PARTER_ID'); $cur_time = sr_getcurtime(time()); $biz_content = array(); $biz_content['out_trade_no'] = $out_trade_no; $biz_content['shopdate'] = sr_getcurtime(time(), 'Ymd'); $biz_content['subject'] = '购买商品'; // $biz_content['total_amount'] = $total_amount; $biz_content['total_amount'] = $total_amount; $biz_content['timeout_express'] = '1h'; $biz_content['currency'] = 'CNY'; $biz_content['business_code'] = '3010002'; $biz_content['seller_id'] = $parterid; $biz_content['bank_type'] = $bank_info['bank_value']; $biz_content['buyer_name'] = $params['cer_name']; $biz_content['buyer_card_number'] = $params['bank_no']; $biz_content['buyer_mobile'] = $params['mobile']; $number = trim($this->ECBEncrypt($params['cer_no'], 'Scf10981')); // 银行卡类型 debit 借记卡 credit信用卡 $biz_content['support_card_type'] = intval($params['bank_type']) == 1 ? 'debit' : 'credit'; if ($params['bank_type'] == 2) { $biz_content['cardCvn2'] = $this->ECBEncrypt($params['security_code'], 'Scf10981'); $biz_content['cardExprDt'] = $this->ECBEncrypt($params['card_expr_time'], 'Scf10981'); } $biz_content['bank_name'] = $bank_info['bank_name']; $biz_content['pyerIDNo'] = $number; $biz_content['pyerIDTp'] = $this->ECBEncrypt('01', 'Scf10981');; $biz_content['bank_account_type'] = 'personal'; $params = [ 'method' => 'ysepay.online.fastpay', 'partner_id' => $parterid, 'timestamp' => $cur_time, 'charset' => 'UTF-8', 'sign_type' => 'RSA', 'notify_url' => env('ZLYS.PAYBACK_URL'), 'version' => '3.4', 'biz_content' => json_encode($biz_content, JSON_UNESCAPED_UNICODE) ]; ksort($params); $params['sign'] = $this->sign($params); // 提交确定支付 sr_log('确认支付:' . json_encode($params)); $result = curlPost($interface_url, $params); sr_log('result:' . $result); $res = json_decode($result); if (isset($res->ysepay_online_fastpay_response->code) && intval($res->ysepay_online_fastpay_response->code) == 10000 && isset($res->ysepay_online_fastpay_response->msg) && intval($res->ysepay_online_fastpay_response->msg) == 'Success') { $trade_no = $res->ysepay_online_fastpay_response->trade_no; $insert = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => '', 'hy_token_id' => '', 'buyer_mobile' => $buy_mobilee, 'trade_no' => $trade_no ]; Db::name('payment')->insert($insert); return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYS' => ['trade_no' => $trade_no]]]); } else { if (isset($res->ysepay_online_fastpay_response->sub_msg)) { return api_error_return($res->ysepay_online_fastpay_response->sub_msg); } else { return api_error_return('支付错误,请联系客服'); } } return api_error_return('支付错误,请联系客服1'); } /** * 电科支付宝支付信息 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfoDiankeZfb($uid, $payData) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $payData); // 接口地址 $apiUrl = env('PAYDK.DKPAY_API_URL','http://1.14.197.47/proxy/pay/unifiedorder'); $date = date('Y-m-d H:i:s'); $out_trade_no = createdOrderSn(); $cacheKey = "caches:payment:dkpay:otn_{$out_trade_no}:{$uid}_{$remarks}_"; RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400); // 测试金额 if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9)); } if ($total_amount > 15000) { $loData = ['payData'=> $payData,'error'=>'大额不能使用支付宝支付', 'date'=>$date]; RedisCache::set($cacheKey.'error', $loData, 2*86400); sr_throw('大额不能使用支付宝支付'); } $params = [ 'appId' => 'dianke', 'version' => '1.0', 'nonceStr' => nonce_str(15), 'orderId' => $out_trade_no, 'amount' => intval($total_amount * 100), 'payChannel' => 'ALP', 'goodsName' => $body? $body : '牛仔裤', 'goodsDesc' => $body? $body : '牛仔裤', 'clientIp' => get_client_ip(), 'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_ZFB_NEWURL'), 'tradeType' => 'QRCODE' ]; ksort($params); $params['sign'] = $this->diankesign($params); // 提交确定支付请求接口 $loData = ['url'=>$apiUrl,'payData'=> $payData,'params'=> $params, 'date'=>$date]; RedisCache::set($cacheKey.'request', $loData, 2*86400); $result = curlPost($apiUrl, $params); $result = $result? json_decode($result, true) : []; $payUrl = isset($result['data'])? $result['data'] : ''; $loData['result'] = $result; $code = isset($result['code'])? $result['code'] : ''; $msg = isset($this->dkError[$code])? $this->dkError[$code] : ''; RedisCache::set($cacheKey.'result', $loData, 2*86400); if ($payUrl) { $payment = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => '', 'hy_token_id' => '' ]; Db::name('payment')->insert($payment); return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]); } else { return api_error_return($msg? '支付错误:'.$msg:'支付错误,请联系客服'); } } /** * 电科云闪付 * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfoDiankeYsf($uid, $payData) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $payData); // 接口地址 $payConfig = PayConfigService::make()->getInfoByChannel($pay_way, $order_type); $apiUrl = isset($payConfig['api_url'])? trim($payConfig['api_url']) : ''; $apiUrl = $apiUrl? $apiUrl : 'http://1.14.197.47/proxy'; $appId = isset($payConfig['app_id'])? trim($payConfig['app_id']) : ''; $signKey = isset($payConfig['sign_key'])? trim($payConfig['sign_key']) : ''; if(empty($payConfig) || empty($appId) || empty($apiUrl) || empty($signKey)){ return api_error_return('支付配置错误,请先配置支付参数'); } $date = date('Y-m-d H:i:s'); $out_trade_no = createdOrderSn(); $cacheKey = "caches:payment:dkysf:otn_{$out_trade_no}:{$uid}_{$remarks}_"; RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400); // 测试金额 if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) { $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9)); } if ($total_amount > 15000) { $loData = ['payData'=> $payData,'error'=>'大额不能使用支付宝支付', 'date'=>$date]; RedisCache::set($cacheKey.'error', $loData, 2*86400); sr_throw('大额不能使用支付宝支付'); } $params = [ 'appId' => $appId, 'version' => '1.0', 'nonceStr' => nonce_str(15), 'orderId' => $out_trade_no, 'amount' => intval($total_amount * 100), 'payChannel' => 'WXP', 'goodsName' => $body? $body : '牛仔裤', 'goodsDesc' => $body? $body : '牛仔裤', 'clientIp' => get_client_ip(), 'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_YSF_URL'), 'tradeType' => 'QRCODE' ]; ksort($params); $params['sign'] = $this->makeSign($params, $signKey); // 提交确定支付请求接口 $payApiUrl = $apiUrl.'/pay/unifiedorder'; $loData = ['url'=>$payApiUrl,'payData'=> $payData,'payconfig'=>$payConfig,'params'=> $params, 'date'=>$date]; RedisCache::set($cacheKey.'request', $loData, 2*86400); $result = curlPost($payApiUrl, $params); $result = $result? json_decode($result, true) : []; $payUrl = isset($result['data'])? $result['data'] : ''; $loData['result'] = $result; $code = isset($result['code'])? $result['code'] : ''; $msg = isset($this->dkError[$code])? $this->dkError[$code] : ''; RedisCache::set($cacheKey.'result', $loData, 2*86400); if ($payUrl) { $payment = [ 'total_fee' => $total_amount, 'trade_type' => $trade_type, 'body' => $body, 'state' => 7, 'out_trade_no' => $out_trade_no, 'pay_way' => $pay_way, 'remarks' => $remarks, 'order_type' => $order_type, 'uid' => $uid, 'voucher_img' => $voucher_img, 'out_trade_no1' => '', 'hy_token_id' => '' ]; Db::name('payment')->insert($payment); return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]); } else { return api_error_return($msg? '支付错误:'.$msg:'支付错误,请联系客服'); } } /** * 银盛-第三方快捷支付 * @param $trade_no * @param $sms_code * @return \think\Response * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function kjPayWithCode($trade_no, $sms_code) { $field = 'id,out_trade_no,total_fee,user_id,buyer_mobile'; $paymentInfo = PaymentService::make()->getCacheInfo($trade_no, 0, $field,false); if (!$paymentInfo) { sr_throw('支付订单错误'); } $out_trade_no = isset($paymentInfo['out_trade_no'])? $paymentInfo['out_trade_no'] : ''; $interface_url = 'https://openapi.ysepay.com/gateway.do'; //正式 $parterid = env('ZLYS.PARTER_ID'); $cur_time = sr_getcurtime(time()); $biz_content = array(); $biz_content['out_trade_no'] = $out_trade_no; $biz_content['buyer_mobile'] = isset($paymentInfo['buyer_mobile'])? $paymentInfo['buyer_mobile'] : ''; $biz_content['mobile_verify_code'] = $sms_code; $params = [ 'method' => 'ysepay.online.fastpay.authorize', 'partner_id' => $parterid, 'timestamp' => $cur_time, 'charset' => 'UTF-8', 'sign_type' => 'RSA', 'notify_url' => env('ZLYS.PAYBACK_URL'), 'version' => '3.0', 'biz_content' => json_encode($biz_content, JSON_UNESCAPED_UNICODE) ]; ksort($params); $params['sign'] = $this->sign($params); // 提交确定支付 $cacheKey = "caches:payment:yskjPay:otn_{$out_trade_no}:"; RedisCache::set($cacheKey.'params', $params, 3600); $result = curlPost($interface_url, $params); RedisCache::set($cacheKey.'result', ['params'=> $params,'result'=> $result], 3600); $res = json_decode($result); $code = isset($res->ysepay_online_fastpay_authorize_response->code)? intval($res->ysepay_online_fastpay_authorize_response->code) : 0; $msg = isset($res->ysepay_online_fastpay_authorize_response->msg)? trim($res->ysepay_online_fastpay_authorize_response->msg) : ''; $sub_msg = isset($res->ysepay_online_fastpay_authorize_response->sub_msg)? trim($res->ysepay_online_fastpay_authorize_response->sub_msg) : ''; if ($code == 10000 && $msg == 'Success') { return api_succ_return('成功'); } else { if ($sub_msg) { return api_error_return($sub_msg); } else { return api_error_return('支付错误,请联系客服'); } } } /** * DES加密方法 * @param $data 传入需要加密的证件号码 * @param $key key为商户号前八位.不足八位的需在商户号前补空格 * @return string 返回加密后的字符串 */ function ECBEncrypt($data, $key) { $encrypted = openssl_encrypt($data, 'DES-ECB', $key, 1); return base64_encode($encrypted); } /** * DES解密方法 * @param $data 传入需要解密的字符串 * @param $key key为商户号前八位.不足八位的需在商户号前补空格 * @return string 返回解密后的证件号码 */ function doECBDecrypt($data, $key) { $encrypted = base64_decode($data); $decrypted = openssl_decrypt($encrypted, 'DES-ECB', $key, 1); return $decrypted; } /** * 签名加密 * @param input data * @return success * @return check * @return msg */ public function sign_encrypt($input) { $return = [ 'success' => 0, 'msg' => '', 'check' => '' ]; $pkcs12 = file_get_contents(env('ZLYS.PFX_PATH')); //私钥 if (openssl_pkcs12_read($pkcs12, $certs, env('ZLYS.PSSSWORD'))) { $privateKey = $certs['pkey']; $publicKey = $certs['cert']; $signedMsg = ""; if (openssl_sign($input['data'], $signedMsg, $privateKey, OPENSSL_ALGO_SHA1)) { $return['success'] = 1; $return['check'] = base64_encode($signedMsg); $return['msg'] = base64_encode($input['data']); } } return $return; } /** * 签名 * @param $data * @return string */ public function sign($data) { ksort($data); $signStr = ""; foreach ($data as $key => $val) { $signStr .= $key . '=' . $val . '&'; } $signStr = trim($signStr, '&'); $sign = $this->sign_encrypt(array('data' => $signStr)); return trim($sign['check']); } /** * 公共支付签名 * @param $data * @return string */ public function makeSign($data, $signKey='') { ksort($data); $signStr = ""; foreach ($data as $key => $val) { $signStr .= $key . '=' . $val . '&'; } $stringSignTemp = $signStr . 'key='.$signKey; $signtemp = md5($stringSignTemp); return strtoupper($signtemp); } /** * 签名 * @param $data * @return string */ public function diankesign($data) { ksort($data); $signStr = ""; foreach ($data as $key => $val) { $signStr .= $key . '=' . $val . '&'; } $stringSignTemp = $signStr . 'key=a05fd6fc1f924b74b83dfd519ce93c28'; $signtemp = \md5($stringSignTemp); return strtoupper($signtemp); } /** * thirdPaySqzBack支付三方sqz签名 * @param $params * @return string */ public function sqzSign($params){ $orderId = isset($params['orderid'])? $params['orderid'] : ''; return md5('orderid=' . $orderId . '&opstate=' . $params['opstate'] . '&ovalue=' . $params['ovalue'] . env('PAYSQZ.SIGNKEY')); } /** * 签名 * @param $data * @return string */ public function diankesigndf($data) { ksort($data); $signStr = ""; foreach ($data as $key => $val) { $signStr .= $key . '=' . $val . '&'; } $stringSignTemp = $signStr . 'key=b91f3a72fe074e39a6add7382de813bc'; $signtemp = \md5($stringSignTemp); return strtoupper($signtemp); } /** * USDT * @param $uid * @param $params * @return \think\Response * @throws Exception */ public function getPayInfoUsdt($uid, $params) { list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params); return api_succ_return('成功'); } /** * 签约银行卡 * @param $uid * @param $post * @return mixed * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function userBankSign($uid, $post) { $pay_success_backurl = env('PAYSQZ.USER_SIGN_BANK'); $parterid = env('PAYSQZ.PARTER'); $phone = $post['phone']; $bankCard = $post['bank_card']; $name = $post['name']; $idCard = $post['id_card']; $orderId = creatBankSignOrderSn($uid); if ($info = UserBankSignService::make()->checkHasSign($uid, $bankCard, 4)) { UserBankSignModel::where('id', $info['id'])->save([ 'status' => 1, 'signorder_id' => $orderId ]); } else { UserBankSignModel::insert([ 'uid' => $uid, 'phone' => $phone, 'bank_card' => $bankCard, 'name' => $name, 'id_card' => $idCard, 'create_time' => sr_getcurtime(time()), 'signorder_id' => $orderId ]); } // 签约参数 $param = [ 'parter' => $parterid, 'userid' => $uid, 'phone' => $phone, 'bankCard' => $bankCard, 'name' => $name, 'idCard' => $idCard, 'orderid' => $orderId, 'callBack' => $pay_success_backurl ]; $keystring = 'parter=' . $parterid . '&userid=' . $uid . '&phone=' . $phone . '&bankCard=' . $bankCard . '&name=' . $name . '&idCard=' . $idCard . '&orderid=' . $orderId . env('PAYSQZ.SIGNKEY'); $param['sign'] = md5($keystring); $cacheKey = "caches:userBankSign:user_{$uid}:{$bankCard}_"; RedisCache::set($cacheKey.'param', $param, 7200); $res = _curlrequest('http://pay.xindonglife.com/PageSign.aspx', $param, 'post'); RedisCache::set($cacheKey.'result', ['param'=> $param,'result'=>$res,'date'=>date('Y-m-d H:i:s')], 7200); $result = json_decode($res); if (isset($result->code) && $result->code == 'SUCCESS') { return $result->sign_url; } else { if (is_string($res)) { sr_throw($res); } else { sr_throw('请求失败,请稍后再试'); } } } /** * 解绑银行卡 * @param $uid * @param $post * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function userUnBankSign($uid, $post) { $parterid = env('PAYSQZ.PARTER'); $orderId = creatBankSignOrderSn($uid); $recordId = isset($post['record_id'])? intval($post['record_id']) : 0; if (!$recordId || !$bankInfo = UserBankSignService::make()->getCacheInfo($recordId, $uid)) { sr_throw('参数错误'); } $param = [ 'parter' => $parterid, 'hy_auth_uid' => $bankInfo['userno'], 'orderId' => $orderId ]; $keystring = 'parter=' . $parterid . '&hy_auth_uid=' . $bankInfo['userno'] . env('PAYSQZ.SIGNKEY'); $param['sign'] = md5($keystring); $cacheKey = "caches:userBankSign:{$uid}_{$recordId}_{$parterid}:"; RedisCache::set($cacheKey.'param', $param, 7200); $res = _curlrequest('http://pay.xindonglife.com/CardUnbinding.aspx', $param, 'post'); RedisCache::set($cacheKey.'result', ['param'=> $param,'result'=> $res,'date'=>date('Y-m-d H:i:s')], 7200); $res = json_decode($res); if (isset($res->code) && $res->code == 'SUCCESS') { RedisCache::keyDel("caches:userBankSign*"); UserBankSignModel::where('id', $post['record_id'])->save(['signorder_u_id' => $orderId, 'status' => 4]); } else { RedisCache::set($cacheKey.'back', ['error'=>'解绑失败','param'=> $param,'result'=> $res,'date'=>date('Y-m-d H:i:s')], 7200); sr_throw('解绑失败'); } } /** * 石学长 银联支付 * @param $uid * @param $params * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function sylSurePay($uid, $params) { if (empty($params['sms_code'])) { sr_throw('参数错误'); } $payment_info = Db::name('payment')->where('out_trade_no1', $params['order_id'])->where('state', 7)->where('uid', $uid)->find(); if (!$payment_info) { sr_throw('参数错误或者订单错误'); } $parterid = env('PAYSQZ.PARTER'); $order_id = creatBankSignOrderSn($uid); $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号 $param = [ 'parter' => $parterid, 'hy_token_id' => $payment_info['hy_token_id'], 'verify_code' => $params['sms_code'], 'orderId' => $out_trade_no1 ]; $keystring = 'parter=' . $parterid . '&hy_token_id=' . $payment_info['hy_token_id'] . '&verify_code=' . $params['sms_code'] . env('PAYSQZ.SIGNKEY'); $param['sign'] = md5($keystring); $res = _curlrequest('http://pay.xindonglife.com/payMentConfirm.aspx', $param, 'post'); $res = json_decode($res); if (isset($res->code) && $res->code == 'SUCCESS') { Db::name('payment')->where('id', $payment_info['id'])->save(['hy_bill_no' => $res->hy_bill_no, 'syl_sureorderid' => $out_trade_no1]); } else { if (isset($res->message)) { sr_throw($res->message); } // {"id":1,"code":"Fail","message":"\u77ed\u4fe1\u9a8c\u8bc1\u7801\u5df2\u8fc7\u671f"} // sr_log('确认失败:'.json_encode($res)); } } /** * pay_money 支付订单的金额 * @param $out_trade_no * @param $pay_money * @param $pay_type * @param $content * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function payBack($out_trade_no, $pay_money, $pay_type, $content, $cacheKey='') { $date = date('Y-m-d H:i:s'); $shopordermodel = new ShopOrderModel(); $services_ordermodel = new ServicesOrderModel(); $params = $content? json_encode($content, true):[]; $cacheKey = $cacheKey? $cacheKey : "caches:payment:callBack:{$out_trade_no}"; RedisCache::set($cacheKey.'_catch', ['params'=>$params,'date'=> $date], 7200); // 验证支付请求信息 $payInfo = PaymentModel::where('out_trade_no', $out_trade_no)->where('state', 7)->find(); $payUid = isset($payInfo['uid'])? $payInfo['uid']:0; if (!$payInfo || $payUid<=0) { $logData = ['params'=>$params,'msg'=>"单号{$out_trade_no}已经回调支付,或支付信息不存在",'date'=> $date]; RedisCache::set($cacheKey.'_error', $logData, 7200); sr_throw('outtradeno已经回调支付:' . $out_trade_no); } $nowTime = date('Y-m-d H:i:s', time()); $userInfo = UserService::make()->getCacheInfo($payUid); if ($payInfo['order_type'] == 6) { $date = sr_getcurtime(time(), 'Y-m-d'); $expire_day = date('Y-m-d', strtotime("$date +1 month")); $payInfo->save(['state' => 6, 'pay_at' => $nowTime]); $services_orderinfo = $services_ordermodel->where('recharge_sn', $payInfo['remarks'])->find(); if ($services_orderinfo) { $services_orderinfo->save(['status' => 2, 'pay_type' => $pay_type, 'updated_time' => $nowTime]); } Db::name('user')->where('id', $services_orderinfo['user_id'])->save([ 'store_type' => 1, 'store_expire_time' => $expire_day ]); } elseif ($payInfo['order_type'] == 4) { $nowTime = date('Y-m-d H:i:s', time()); $payInfo->save(['state' => 6, 'pay_at' => $nowTime]); $order_info = $shopordermodel->where('order_sn', $payInfo['remarks'])->find(); Db::name('user')->whereIn('id', $userInfo['path'])->inc('total_team_income', $payInfo['total_fee'])->update(); Db::name('user')->whereIn('id', $userInfo['id'])->inc('total_team_income', $payInfo['total_fee'])->update(); Db::name('user')->where('id', $userInfo['id'])->inc('total_income', $payInfo['total_fee'])->update(); $order_info->save(['status' => 1, 'pay_type' => $pay_type, 'updated_time' => $nowTime]); // 增加销量 $orderGoods = OrderGoods::where(['order_id' => $order_info['order_id']])->select()->toArray(); foreach ($orderGoods as $k => $v) { ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update(); } $uid = $payInfo['uid']; Db::name('thirdpay_back')->insert([ 'out_order_no' => $out_trade_no, 'content' => $content, 'create_time' => sr_getcurtime(time()), 'type' => $pay_type, 'uid' => $uid, 'money' => $pay_money ]); // 赠送积分 edit_user_score(3, $uid, $order_info['rebate_score'], 0, $payInfo['id']); } } /** * ay_money 代付回调金额 * @param $out_trade_no * @param $pay_money * @param $params * @param $content * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function payDfBack($out_trade_no, $pay_money, $params, $content) { if (isset($params['status'])) { $model = new WithDrawLogModel(); $info = $model->where('out_biz_no', $out_trade_no)->find(); if (!$info) { return; } if ($info && $info['status'] == 4) { if ($params['status'] == 1) { // 代付成功 $info->save(['status' => 1]); } else { Db::startTrans(); try { Db::startTrans();//开启事务 $info = $model->where('out_biz_no', $out_trade_no)->find(); $user_info = Db::name('user')->where('id', $info['uid'])->lock(true)->find(); $res = edit_user_money(10, $info['uid'], $info['apply_money']); Db::name('action_liangb')->insert([ 'create_time' => sr_getcurtime(time()), 'wd_id' => $out_trade_no ]); // 代付失败 $info->save(['zfb_error' => $content, 'status' => 3]); Db::commit(); } catch (\Exception $e) { Db::rollback(); sr_log('代付回调报错'); } } } } } /** * @param $uid * @param $pay_info * @param $yeji * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function scaleAgentMoney($uid, $pay_info, $yeji) { $is_privince_get = false; $is_city_get = false; $money = intval($pay_info['total_fee'] / 100) * 100; $user_info = Db::name('user')->where('id', $uid)->find(); $path = $user_info['path']; // sr_log('path:'.$path); $arr = explode(',', $path); $arr = array_reverse($arr); $ids = $arr; $ids = implode(',', $ids); $order = 'field(id,' . $ids . ')'; $users = Db::name('user')->where('id', 'in', $arr)->field('id,level,agent_type')->order(Db::raw($order))->select()->toArray(); foreach ($users as $key => $val) { if ($val['agent_type'] == 1) { if (!$is_privince_get) { if ($is_city_get) { edit_user_money(17, $val['id'], $money * 0.5 / 100, 0, $pay_info['remarks']); } else { edit_user_money(17, $val['id'], $money / 100, 0, $pay_info['remarks']); } $is_privince_get = true; } } if ($val['agent_type'] == 2) { if (!$is_privince_get) { edit_user_money(18, $val['id'], $money * 0.5 / 100, 0, $pay_info['remarks']); } $is_city_get = true; } } } /** * pay_money 余额支付订单的金额 * @param $order_sn * @param $pay_type * @param $content * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function payBalanceDown($order_sn, $pay_type, $content) { $paymodel = new PaymentModel(); $shopordermodel = new ShopOrderModel(); $usermodel = new UserModel(); $order_info = $shopordermodel->where('order_sn', $order_sn)->find(); $nowTime = date('Y-m-d H:i:s', time()); $user_info = $usermodel->where('id', $order_info['user_id'])->find(); $order_info->save(['status' => 1, 'pay_type' => $pay_type, 'updated_time' => $nowTime]); // 增加销量 $orderGoods = OrderGoods::where(['order_id' => $order_info['order_id']])->select()->toArray(); foreach ($orderGoods as $k => $v) { ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update(); } $uid = $order_info['user_id']; Db::name('thirdpay_back')->insert([ 'out_order_no' => '', 'content' => $content, 'create_time' => sr_getcurtime(time()), 'type' => $pay_type, 'uid' => $uid, 'money' => $order_info['payment'] ]); // 给用户添加业绩 $pay_info = $paymodel->where('remarks', $order_sn)->where('state', 6)->find(); // 赠送积分 edit_user_score(1, $uid, $order_info['rebate_score']); $this->update_user_yeji($uid, $user_info, $order_info, $pay_info); } /** * @param $uid * @param $user_info * @param $order_info * @param $pay_info * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function update_user_yeji($uid, $user_info, $order_info, $pay_info) { // 计算用户的yeji $yeji = 0; // 根据所送的积分算业绩 if ($user_info['performance_me'] < 10000) { if (($user_info['performance_me'] + $order_info['rebate_score']) > 10000) { $yeji = 10000 - $user_info['performance_me']; incUserPerformance($uid, $yeji); } else { $yeji = $order_info['rebate_score']; incUserPerformance($uid, $yeji); } } if ($yeji > 0) { // 如果增加的业绩大于0 计算省代跟市代 // $this->scaleAgentMoney($order_info['user_id'], $pay_info, $yeji); } } /** * 手续费 * @param $uid * @param $pay_info * @param $nowTime * @param int $type * @return false */ public function update_user_free($uid, $pay_info, $nowTime, $type = 1){ // return false; } }