| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223 |
- <?php
- /**
- * 支付宝支付
- */
- namespace app\api\services;
- use app\common\model\PaymentModel;
- use app\common\model\ServicesOrderModel;
- use app\common\model\ShopGoodsModel;
- use app\common\model\ShopOrderGoodsModel as OrderGoods;
- use app\common\model\ShopOrderModel;
- use app\common\model\ShopOrderModel as Order;
- use app\common\model\UserBankSignModel;
- use app\common\model\UserModel;
- use app\common\model\WithDrawLogModel;
- use app\common\service\PaymentService;
- use app\common\service\UserBankSignService;
- use app\common\service\UserService;
- use think\Exception;
- use think\facade\Db;
- use utils\RedisCache;
- class ThirdPayServices extends BasePayServices
- {
- /**
- * 多乐宝支付宝支付
- * @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;
- 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('支付错误,请联系客服');
- }
- }
- /**
- * 电科云闪付
- * @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);
- // 接口地址
- $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;
- 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('支付错误,请联系客服');
- }
- }
- /**
- * 银盛-第三方快捷支付
- * @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 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;
- }
- }
|