ThirdPayServices.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  1. <?php
  2. /**
  3. * 支付宝支付
  4. */
  5. namespace app\api\services;
  6. use app\common\model\PaymentModel;
  7. use app\common\model\ServicesOrderModel;
  8. use app\common\model\ShopGoodsModel;
  9. use app\common\model\ShopOrderGoodsModel as OrderGoods;
  10. use app\common\model\ShopOrderModel;
  11. use app\common\model\ShopOrderModel as Order;
  12. use app\common\model\UserBankSignModel;
  13. use app\common\model\UserModel;
  14. use app\common\model\WithDrawLogModel;
  15. use app\common\service\UserBankSignService;
  16. use app\common\service\UserService;
  17. use think\Exception;
  18. use think\facade\Db;
  19. use utils\RedisCache;
  20. class ThirdPayServices extends BasePayServices
  21. {
  22. /**
  23. * 多乐宝支付宝支付
  24. * @param $uid
  25. * @param $params
  26. * @return \think\Response
  27. * @throws Exception
  28. */
  29. public function getPayInfo($uid, $params)
  30. {
  31. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  32. $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  33. $params = [
  34. 'appid' => '9d5e3cb9a4946cf28a42b99f4f8bf978',
  35. 'method' => 'payment.wxjsapp',
  36. 'merchant' => '220951176399985946',
  37. 'body' => '购买商品',
  38. 'external_order_no' => $out_trade_no1, // 我们自己的订单号
  39. 'total_amount' => $total_amount,
  40. // 'notify_url'=>'http://api.meikangjw.com/api/aliResult'
  41. 'notify_url' => 'http://zy.suncorex.com:2080/api/aliResultDLB'
  42. ];
  43. $sign = thirdPayGetSign($params, '897d9ea909093173b24dd89c772181e4');
  44. $params['sign'] = $sign;
  45. $res = _curlrequest('http://openpay.duolaibei.com/api/gateway', $params, 'post');
  46. $res = json_decode($res);
  47. if ($res && isset($res->code) && $res->code == 200) {
  48. $out_trade_no = $res->content->order_no;
  49. $this->setPaymentOrder(compact('body', 'out_trade_no', 'out_trade_no1', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 5);
  50. // return api_succ_return(['msg'=>'请求成功', 'data'=>['thirdpaydlbalipay'=>['url'=>$res->content->url]]]);
  51. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpaydlbwx' => ['url' => $res->content->url, 'jsappid' => $res->content->JSAPPID]]]);
  52. } else {
  53. return api_error_return('获取失败');
  54. }
  55. }
  56. /**
  57. * 多乐宝微信支付
  58. * @param $uid
  59. * @param $params
  60. * @return \think\Response
  61. * @throws Exception
  62. */
  63. public function getWxPayInfo($uid, $params)
  64. {
  65. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  66. $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  67. $params = [
  68. 'appid' => '9d5e3cb9a4946cf28a42b99f4f8bf978',
  69. 'method' => 'payment.wxjsapp',
  70. 'merchant' => '220951176399985946',
  71. 'body' => '购买商品',
  72. 'external_order_no' => $out_trade_no1, // 我们自己的订单号
  73. 'total_amount' => $total_amount,
  74. // 'notify_url'=>'http://api.meikangjw.com/api/aliResult'
  75. 'notify_url' => 'http://zy.suncorex.com:2080/api/wechatResultDLB'
  76. ];
  77. $sign = thirdPayGetSign($params, '897d9ea909093173b24dd89c772181e4');
  78. $params['sign'] = $sign;
  79. // return $params;
  80. $res = _curlrequest('http://openpay.duolaibei.com/api/gateway', $params, 'post');
  81. // sr_log(sr_getcurtime(time()).$res);
  82. // {"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"}}
  83. $res = json_decode($res);
  84. if ($res && isset($res->code) && $res->code == 200) {
  85. $out_trade_no = $res->content->order_no;
  86. $this->setPaymentOrder(compact('body', 'out_trade_no', 'out_trade_no1', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 5);
  87. // return api_succ_return(['msg'=>'请求成功', 'data'=>['thirdpaydlbalipay'=>['url'=>$res->content->url]]]);
  88. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpaydlbwx' => ['url' => $res->content->url, 'jsappid' => $res->content->JSAPPID]]]);
  89. } else {
  90. return api_error_return('获取失败');
  91. }
  92. }
  93. /**
  94. * 畅联微信支付
  95. * @param $uid
  96. * @param $params
  97. * @return \think\Response
  98. * @throws Exception
  99. */
  100. public function getWxPayInfoCL($uid, $params)
  101. {
  102. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  103. $out_trade_no = 'CL' . rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  104. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  105. $error_url = getWebUrl() . '/api/thirdPayClError';
  106. $params = [
  107. 'appid' => '1059174',
  108. 'pay_type' => 'partnerJs',
  109. 'amount' => sprintf("%.2f", $total_amount),
  110. 'callback_url' => getWebUrl() . '/api/wechatResultCL',
  111. 'success_url' => $success_url,
  112. 'error_url' => $error_url,
  113. 'extend' => '{"body":"购买商品"}',
  114. 'out_trade_no' => $out_trade_no
  115. ];
  116. // sr_log(json_encode($params));
  117. $sign = thirdPayGetSignCL('XMLfjHMPOGexsSaadIWSVCNG0XJBClZZ', $params);
  118. $params['sign'] = $sign;
  119. // sr_log(json_encode($params));
  120. // return $params;
  121. $res = _curlrequest('https://api.payunk.com/index/unifiedorder?format=json', $params, 'post');
  122. sr_log(sr_getcurtime(time()) . $res);
  123. $res = json_decode($res);
  124. if ($res && isset($res->code) && $res->code == 200) {
  125. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 7);
  126. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpayclwx' => ['url' => $res->url, 'success_url' => $success_url, 'error_url' => $error_url]]]);
  127. } else {
  128. return api_error_return('获取失败');
  129. }
  130. }
  131. /**
  132. * 畅联支付宝支付 type aban(A版本) h5ban(h5版本) dban(D版本)
  133. * @param $uid
  134. * @param $params
  135. * @param $type
  136. * @return \think\Response
  137. * @throws Exception
  138. */
  139. public function getAliPayInfoCL($uid, $params, $type)
  140. {
  141. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  142. // 这是测试 线要干掉
  143. // $total_amount = floatval('0.'.mt_rand(1, 3).mt_rand(1, 9));
  144. // $total_amount = 0.01;
  145. $out_trade_no = 'CL' . rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  146. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  147. $error_url = getWebUrl() . '/api/thirdPayClError';
  148. $type_arr = [
  149. 'aban' => 'alipayApp',
  150. 'h5ban' => 'adapayH5',
  151. 'dban' => 'alipayPrecreate'
  152. ];
  153. $params = [
  154. 'appid' => '1059174',
  155. 'pay_type' => $type_arr[$type],
  156. 'amount' => sprintf("%.2f", $total_amount),
  157. 'callback_url' => getWebUrl() . '/api/AliResultCL',
  158. 'success_url' => $success_url,
  159. 'error_url' => $error_url,
  160. 'extend' => '{"body":"购买商品","subject":"购买商品"}',
  161. 'out_trade_no' => $out_trade_no
  162. ];
  163. // sr_log(json_encode($params));
  164. $sign = thirdPayGetSignCL('XMLfjHMPOGexsSaadIWSVCNG0XJBClZZ', $params);
  165. $params['sign'] = $sign;
  166. // sr_log(json_encode($params));
  167. // return $params;
  168. $res = _curlrequest('https://api2.payunk.com/index/unifiedorder?format=json', $params, 'post');
  169. // sr_log(sr_getcurtime(time()).$res);
  170. $res = json_decode($res);
  171. if ($res && isset($res->code) && $res->code == 200) {
  172. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), ($type == 'aban' ? 10 : 8));
  173. return api_succ_return(['msg' => '请求成功', 'data' => ['thirdpayclali' => ['url' => $res->url, 'success_url' => $success_url, 'error_url' => $error_url]]]);
  174. } else {
  175. return api_error_return('获取失败');
  176. }
  177. }
  178. /**
  179. * mo宝 富有 银联支付
  180. * @param $uid
  181. * @param $paramscon
  182. * @return \think\Response
  183. * @throws Exception
  184. */
  185. public function getBankPayInfoFY($uid, $paramscon)
  186. {
  187. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $paramscon);
  188. // 商户号
  189. $mchnt_cd = env('api.PAY_FUYOU_MCHNT_id');
  190. $time = time();
  191. $time_end = time() + 2 * 60 * 60;
  192. $order_date = sr_getcurtime($time, 'Ymd');
  193. $order_timestart = sr_getcurtime($time, 'YmdHis');
  194. $order_timeend = sr_getcurtime($time_end, 'YmdHis');
  195. $order_id = $paramscon['order_id'];
  196. $out_trade_no = 'FYYL' . $order_id;
  197. $mess_arr = ['mchnt_cd' => $mchnt_cd, 'order_date' => $order_date, 'order_id' => $paramscon['order_id'], 'ver' => '1.0.0'];
  198. // sr_log('message_json'.json_encode($mess_arr));
  199. $params = ['mchnt_cd' => $mchnt_cd, 'message' => RSA_openssl(json_encode($mess_arr))];
  200. // 测试
  201. // $url = 'https://aggapp-test.fuioupay.com/token.fuiou';
  202. // 正式
  203. $url = 'https://aggapp.fuioupay.com/token.fuiou';
  204. $ch = curl_init();
  205. curl_setopt($ch, CURLOPT_URL, $url);
  206. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  207. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  208. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  209. $headers = ['Content-type: application/json'];
  210. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  211. // POST数据
  212. curl_setopt($ch, CURLOPT_POST, 1);
  213. // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  214. // 把post的变量加上
  215. $data = json_encode($params);
  216. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  217. $output = curl_exec($ch);
  218. curl_close($ch);
  219. // sr_log('ccc'.$output);
  220. $rsares = json_decode($output);
  221. $res_decode = json_decode(RSA_openssl($rsares->message, 'decode'));
  222. sr_log('ccc' . json_encode($res_decode));
  223. if (isset($res_decode->order_date) && isset($res_decode->order_token) && isset($res_decode->mchnt_cd) && isset($res_decode->order_id)) {
  224. if ($res_decode->mchnt_cd == $mchnt_cd && $res_decode->order_id == $order_id) {
  225. $bank_params = [
  226. 'mchnt_cd' => $mchnt_cd,
  227. 'order_date' => $order_date,
  228. 'order_amt' => bcmul($total_amount, 100, 0),
  229. 'order_id' => $order_id,
  230. 'page_notifyurl' => ($paramscon['app_sources'] == 'ios' ? getWebUrl() . '/api/thirdPayClSuccess' : AESjiami(getWebUrl() . '/api/thirdPayClSuccess')),
  231. 'back_notifyurl' => ($paramscon['app_sources'] == 'ios' ? getWebUrl() . '/api/BankResultFY' : AESjiami(getWebUrl() . '/api/BankResultFY')),
  232. 'order_timestart' => $order_timestart,
  233. 'order_timeend' => $order_timeend,
  234. 'order_token' => $res_decode->order_token
  235. ];
  236. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 9);
  237. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayflyl' => $bank_params]]);
  238. } else {
  239. return api_error_return('获取失败,订单校验失败1');
  240. }
  241. } else {
  242. return api_error_return('获取失败,订单校验失败');
  243. }
  244. return api_error_return('获取失败');
  245. }
  246. /**
  247. * 易票联 支付宝支付
  248. * @param $uid
  249. * @param $params
  250. * @return \think\Response
  251. * @throws Exception
  252. */
  253. public function getZfbPayInfoYPL($uid, $params)
  254. {
  255. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  256. $order_id = $params['order_id'];
  257. $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000);
  258. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  259. $error_url = getWebUrl() . '/api/thirdPayClError';
  260. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  261. $orderInfo = array();
  262. $orderInfo['Id'] = 'id34535';
  263. $orderInfo['businessType'] = '130001';
  264. $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1));
  265. $params = [
  266. 'areaInfo' => '440106',
  267. 'attachData' => 'attachData',
  268. 'clientIp' => request()->ip(),
  269. 'customerCode' => '562012003860535',
  270. 'nonceStr' => nonce_str(32),
  271. 'notifyUrl' => $notify_url,
  272. 'orderInfo' => $orderInfo,
  273. 'outTradeNo' => $out_trade_no,
  274. 'payAmount' => bcmul($total_amount, 100, 0),
  275. 'payCurrency' => 'CNY',
  276. 'payMethod' => '7',
  277. 'redirectUrl' => $success_url,
  278. 'transactionStartTime' => date('YmdHis'),
  279. 'version' => '3.0'
  280. ];
  281. sr_log(json_encode($params));
  282. // 测试
  283. // $url = 'http://test-efps.epaylinks.cn';
  284. // 正式
  285. $url = 'https://efps.epaylinks.cn';
  286. $url = $url . '/api/txs/pay/NativePayment';
  287. $sign = $this->YPLsign(json_encode($params));
  288. $headers = [
  289. // 'Content-type: application/json',
  290. 'x-efps-sign-no' => '562012003860535001',
  291. 'x-efps-sign-type' => 'SHA256withRSA',
  292. 'x-efps-sign' => $sign,
  293. 'x-efps-timestamp' => date('YmdHis')
  294. ];
  295. sr_log(json_encode('header' . json_encode($headers)));
  296. // 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==
  297. $response = $this->http_post_json($url, json_encode($params), $sign);
  298. sr_log($response);
  299. if ($response && $response[0] == 200) {
  300. $re_data = json_decode($response[1], true);
  301. if ($re_data['returnCode'] == '0000') {
  302. $payurl = $re_data['codeUrl'];
  303. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 12);
  304. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPL' => ['pay_url' => $payurl]]]);
  305. // return api_succ_return(['msg'=>'成功', 'data'=>['thirdpay'=>['url'=>$payurl]]]);
  306. //
  307. }
  308. } else {
  309. return api_error_return('获取失败,请联系客服');
  310. }
  311. return api_error_return('获取失败,请联系客服');
  312. }
  313. /**
  314. * 易票联云闪付
  315. * @param $uid
  316. * @param $params
  317. * @return \think\Response
  318. * @throws Exception
  319. */
  320. public function getYsfPayInfoYPL($uid, $params)
  321. {
  322. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  323. // 商户号
  324. $mchnt_cd = env('api.PAY_FUYOU_MCHNT_id');
  325. $order_id = $params['order_id'];
  326. $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000);
  327. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  328. $error_url = getWebUrl() . '/api/thirdPayClError';
  329. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  330. $orderInfo = array();
  331. $orderInfo['Id'] = 'id34535';
  332. $orderInfo['businessType'] = '130001';
  333. $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1));
  334. // $order_timestart = sr_getcurtime($time, 'YmdHis');
  335. $params = [
  336. 'areaInfo' => '440106',
  337. 'attachData' => 'attachData',
  338. 'clientIp' => request()->ip(),
  339. 'customerCode' => '562012003860535',
  340. 'nonceStr' => nonce_str(32),
  341. 'notifyUrl' => $notify_url,
  342. 'orderInfo' => $orderInfo,
  343. 'outTradeNo' => $out_trade_no,
  344. 'payAmount' => bcmul($total_amount, 100, 0),
  345. 'payCurrency' => 'CNY',
  346. 'redirectUrl' => $success_url,
  347. 'transactionStartTime' => date('YmdHis'),
  348. 'version' => '3.0'
  349. ];
  350. sr_log('ypl' . json_encode($params));
  351. // 测试
  352. // $url = 'http://test-efps.epaylinks.cn';
  353. // 正式
  354. $url = 'https://efps.epaylinks.cn';
  355. $url = $url . '/api/txs/pay/UnionAppPayment';
  356. sr_log('yplurl:' . $url);
  357. $sign = $this->YPLsign(json_encode($params));
  358. $headers = [
  359. // 'Content-type: application/json',
  360. 'x-efps-sign-no' => '562012003860535001',
  361. 'x-efps-sign-type' => 'SHA256withRSA',
  362. 'x-efps-sign' => $sign,
  363. 'x-efps-timestamp' => date('YmdHis')
  364. ];
  365. sr_log('yplheader' . json_encode($headers));
  366. $response = $this->http_post_json($url, json_encode($params), $sign);
  367. sr_log('yplresponse' . json_encode($response));
  368. if ($response && $response[0] == 200) {
  369. $re_data = json_decode($response[1], true);
  370. if ($re_data['returnCode'] == '0000') {
  371. $tn = $re_data['tn'];
  372. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 13);
  373. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPLYsf' => ['tn' => $tn]]]);
  374. //
  375. }
  376. } else {
  377. return api_error_return('获取失败,请联系客服');
  378. }
  379. return api_error_return('获取失败,请联系客服');
  380. }
  381. /**
  382. * 汇付支付宝支付
  383. * @param $uid
  384. * @param $params
  385. * @return \think\Response
  386. * @throws Exception
  387. */
  388. public function getHfPayInfoHF($uid, $params)
  389. {
  390. // 加载基础 adapay 基础类
  391. // SDK 初始化文件加载
  392. include_once "../extend/thirdpay/AdapaySdk/init.php";
  393. // 在文件中设置 DEBUG 为 true 时, 则可以打印日志到指定的日志目录下 LOG_DIR
  394. include_once "../extend/thirdpay/config.php";
  395. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  396. // 这是测试 线要干掉
  397. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  398. // 这是测试 线要干掉
  399. $total_amount = floatval('1.' . mt_rand(1, 3) . mt_rand(1, 9));
  400. }
  401. $time_end = time() + 2 * 60 * 60;
  402. $order_timeend = sr_getcurtime($time_end, 'YmdHis');
  403. $order_id = $params['order_id'];
  404. $out_trade_no = 'HFPAY' . $order_id . mt_rand(1, 10000);
  405. # 初始化支付类
  406. $payment = new \AdaPaySdk\Payment();
  407. # 支付设置
  408. $payment_params = array(
  409. "app_id" => "app_3906a188-adf7-4776-a126-fd1996b178d3",
  410. "order_no" => $out_trade_no,
  411. "pay_channel" => "alipay",
  412. "time_expire" => $order_timeend,
  413. "pay_amt" => strval(intval($total_amount)) . '.00',
  414. "goods_title" => "日用生活用品",
  415. "goods_desc" => "多宝购买商品",
  416. "description" => "购买商品",
  417. "notify_url" => getWebUrl() . '/api/ZfbResultHF'
  418. );
  419. sr_log('汇付支付请求参数:' . json_encode($payment_params));
  420. # 发起支付
  421. $payment->create($payment_params);
  422. # 对支付结果进行处理
  423. if ($payment->isError()) {
  424. //失败处理
  425. $response = $payment->result;
  426. sr_log('hfresponseerror' . json_encode($response));
  427. return api_error_return('获取失败,请联系客服');
  428. } else {
  429. //成功处理
  430. $response = $payment->result;
  431. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 14);
  432. $bank_params = [
  433. 'url' => $response['expend']['pay_info']
  434. ];
  435. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayhf' => $bank_params]]);
  436. }
  437. return api_error_return('获取失败,请联系客服');
  438. }
  439. /**
  440. * 易票联统一支付
  441. * @param $uid
  442. * @param $params
  443. * @return \think\Response
  444. * @throws Exception
  445. */
  446. public function getYsfPayInfoTY($uid, $params)
  447. {
  448. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  449. // 商户号
  450. $order_id = $params['order_id'];
  451. $out_trade_no = 'YPL' . $order_id . mt_rand(1, 10000);
  452. $success_url = getWebUrl() . '/api/thirdPayClSuccess';
  453. $error_url = getWebUrl() . '/api/thirdPayClError';
  454. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  455. // 商品订单信息
  456. $orderInfo = array();
  457. $orderInfo['Id'] = 'id34535';
  458. $orderInfo['businessType'] = '130001';
  459. $orderInfo['goodsList'] = array(array('name' => 'pay', 'number' => 'one', 'amount' => 1));
  460. $params = [
  461. 'areaInfo' => '440106',
  462. 'attachData' => 'attachData',
  463. 'clientIp' => request()->ip(),
  464. 'customerCode' => '562012003860535',
  465. 'nonceStr' => nonce_str(32),
  466. 'notifyUrl' => $notify_url,
  467. 'orderInfo' => $orderInfo,
  468. 'outTradeNo' => $out_trade_no,
  469. 'payAmount' => bcmul($total_amount, 100, 0),
  470. 'payCurrency' => 'CNY',
  471. 'redirectUrl' => $success_url,
  472. 'transactionStartTime' => date('YmdHis'),
  473. 'version' => '3.0'
  474. ];
  475. sr_log('ypl' . json_encode($params));
  476. // 测试
  477. // $url = 'http://test-efps.epaylinks.cn';
  478. // 正式
  479. $url = 'https://efps.epaylinks.cn';
  480. $url = $url . '/api/txs/pay/UnifiedPayment';
  481. sr_log('yplurl:' . $url);
  482. $sign = '333';
  483. $headers = [
  484. 'x-efps-sign-no' => '562012003860535001',
  485. 'x-efps-sign-type' => 'SHA256withRSA',
  486. 'x-efps-sign' => $sign,
  487. 'x-efps-timestamp' => date('YmdHis')
  488. ];
  489. sr_log('yplheader' . json_encode($headers));
  490. $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way', 'voucher_img'), 13);
  491. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYPLYsf' => ['tn' => $out_trade_no]]]);
  492. }
  493. /**
  494. * 易票联进件申请
  495. * @param $uid
  496. * @param $params
  497. * @return \think\Response
  498. */
  499. public function getYsfPayJJSubmit($uid, $params)
  500. {
  501. $time = time();
  502. $time_end = time() + 2 * 60 * 60;
  503. $order_date = sr_getcurtime($time, 'Ymd');
  504. $order_timestart = sr_getcurtime($time, 'YmdHis');
  505. $order_timeend = sr_getcurtime($time_end, 'YmdHis');
  506. $success_url = 'https://api.meikangjw.com/api/yplApplyResult';
  507. $error_url = getWebUrl() . '/api/thirdPayClError';
  508. $notify_url = getWebUrl() . '/api/ZfbResultYPL';
  509. $paper = array();
  510. //-------------------------------------------------------
  511. // 经营地址
  512. $paper['businessAddress'] = '重庆市渝北区回兴街道宝圣大道209号西政国际学术交流中心1幢';
  513. // 证件人姓名
  514. $paper['certificateName'] = '胡明冬';
  515. // 证件效期(截止) 无限期填写“长期”
  516. $paper['certificateTo'] = '20270104';
  517. // 省
  518. $paper['province'] = '500000';
  519. // 市
  520. $paper['city'] = '500100';
  521. // 区
  522. $paper['area'] = '500112';
  523. // MCC 码 参考附件商户类别 MCC 码
  524. $paper['mcc'] = '5399';
  525. // 联系人姓名
  526. $paper['contactPerson'] = '胡明冬';
  527. // 联系人手机号码
  528. $paper['contactPhone'] = '13330218461';
  529. // 邮箱地址
  530. $paper['email'] = '845313908@qq.com';
  531. // $paper['isCc']='1';
  532. // 证件号码
  533. $paper['lawyerCertNo'] = '513002199602181213';
  534. //// 证件背面
  535. $paper['lawyerCertPhotoBack'] = 'https://api.meikangjw.com/upload/20220707/42b46e4e6b82c81b9bb3c72d1c630c80.jpg';
  536. /// // 证件正面照
  537. $paper['lawyerCertPhotoFront'] = 'https://api.meikangjw.com/upload/20220707/5fa0ff6cc891e545c1aa423db7613f63.jpg';
  538. // 0:身份证;1:居住证;2:签证;3:护照;4:户口本;5:军人证;6:团员证;7:党员证;8:港澳通行证;9:台胞证;11:临时身份证;12:回乡证;13:营业执照:14:组织机构代码证;15:驾驶证;99:其他目前仅支持 0:身份证
  539. $paper['lawyerCertType'] = '0';
  540. // 开户银行 填写银行名称,参见附件银行
  541. $paper['openBank'] = '中国工商银行';
  542. // 开户行联行号 settleAccountType 为“1:对公账户”时必填,参见附件支行及联行号 查询不到 看链接查询 https://www.lianhanghao.com/
  543. $paper['openBankCode'] = '102290010045';
  544. // 开户支行 settleAccountType 为“1:对公账户”时必填
  545. $paper['openSubBank'] = '中国工商银行股份有限公司上海市闵行支行';
  546. // 客服电话
  547. $paper['serviceTel'] = '13330218461';
  548. // 结算账户名 ①merchantType=1、2 且 settleAccountType=1 时,需与merchantName 一致; ②merchantType=1、2 且 settleAccountType=2 时,需与lawyerName 一致; ③merchantType=3 时,需与 certificateName 一致。
  549. $paper['settleAccount'] = '胡明冬';
  550. // 1:个体工商户;2:企业;3:个人(小微);4:政府 事业单位;9:其他组织
  551. $paper['merchantType'] = '3';
  552. // 结算账户类型 1:对公账户 2:法人账户 3:授权对公 4:授权对私 merchantType=3 时必填 2。
  553. $paper['settleAccountType'] = '2';
  554. // 银行卡正面照
  555. $paper['bankCardPhotoFront'] = 'https://api.meikangjw.com/upload/20220707/1d80b9edb7773c0d1313270a9b39da6c.jpeg';
  556. // 银行卡背面照
  557. $paper['bankCardPhotoBack'] = 'https://api.meikangjw.com/upload/20220707/aff7377fff22225bff320a51cddaa75d.jpeg';
  558. // 结算账户号
  559. $paper['settleAccountNo'] = '6222031001022713072';
  560. // 提现方式 1:自动提现;2:手动提现
  561. $paper['settleTarget'] = '2';
  562. // 商户简称
  563. $paper['shortName'] = 'hmd_xiaowei';
  564. // 门店内景照
  565. $paper['storeHallPhoto'] = 'https://api.meikangjw.com/upload/20220711/a9ed2ef249e919c8432f756bd4b29a0a.jpg';
  566. // 门店门头照
  567. $paper['storeHeadPhoto'] = 'https://api.meikangjw.com/upload/20220711/e3491c28c5096fc20b6c84efff3b003e.jpg';
  568. // 门店外景照
  569. $paper['storeShopPhoto'] = 'https://api.meikangjw.com/upload/20220711/e3491c28c5096fc20b6c84efff3b003e.jpg';
  570. // $paper['unionShortName']='蜀盛锦蓉店铺';
  571. // refundFeeRate 退款手续费费率
  572. // settleCycle 结算周期
  573. // stage 手续费费率
  574. // stage.amountFrom 阶梯起始交易金额
  575. // stage.feePer 单笔收费
  576. // stage.feeRate 按比例收费
  577. // 代付带储蓄卡
  578. $b_withdraw = array('bankStage' => [], 'businessCode' => 'WITHDRAW', 'creditcardsEnabled' => 0, 'refundEnabled' => 1, 'refundFeePer' => 0, 'refundFeeRate' => 0, 'settleCycle' => 'D+0', 'stage' => array(array('amountFrom' => 0, 'feePer' => 200)));
  579. // 支付宝 主扫支付
  580. $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)));
  581. // 支付宝生活号支付
  582. $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)));
  583. $business = array($b_withdraw, $b_alinav, $b_alinav1);
  584. $params = [
  585. // 是否收单 1 是,0 否
  586. 'acceptOrder' => '1',
  587. // 平台商户编号
  588. 'acqSpId' => '562012003860535',
  589. // 审核回调地址
  590. 'backUrl' => $success_url,
  591. 'business' => $business,
  592. // 填写进件的小微名字
  593. 'merchantName' => '重庆闲食有趣',
  594. // 是否开户
  595. 'openAccount' => '1',
  596. 'paper' => json_encode($paper),
  597. // 更换子商户信息必传
  598. 'acqMerId' => 562227003867484
  599. ];
  600. sr_log('yplpaper' . json_encode($paper));
  601. sr_log('ypl' . json_encode($params));
  602. // 正式
  603. $url = 'https://efps.epaylinks.cn';
  604. // 商户进件或者补件
  605. $url = $url . '/api/cust/SP/Merchant/apply';
  606. sr_log('yplurl:' . $url);
  607. $sign = $this->YPLsign(json_encode($params));
  608. $headers = [
  609. 'x-efps-sign-no' => '562012003860535001',
  610. 'x-efps-sign-type' => 'SHA256withRSA',
  611. 'x-efps-sign' => $sign,
  612. 'x-efps-timestamp' => date('YmdHis')
  613. ];
  614. sr_log('yplheader' . json_encode($headers));
  615. $response = $this->http_post_json($url, json_encode($params), $sign);
  616. sr_log('yplresponse' . json_encode($response));
  617. if ($response && $response[0] == 200) {
  618. $re_data = json_decode($response[1], true);
  619. if ($re_data['respCode'] == '0000') {
  620. return api_succ_return('成功');
  621. } else {
  622. return api_error_return($re_data['respMsg']);
  623. }
  624. } else {
  625. return api_error_return('获取失败,请联系客服');
  626. }
  627. return api_error_return('获取失败,请联系客服');
  628. return api_error_return('获取失败');
  629. }
  630. /**
  631. * http请求
  632. * @param $url
  633. * @param $jsonStr
  634. * @param $sign
  635. * @return array
  636. */
  637. protected function http_post_json($url, $jsonStr, $sign)
  638. {
  639. $ch = curl_init();
  640. $headers = array(
  641. 'Content-Type: application/json; charset=utf-8',
  642. 'Content-Length: ' . strlen($jsonStr),
  643. 'x-efps-sign-no:' . '562012003860535001',
  644. 'x-efps-sign-type:SHA256withRSA',
  645. 'x-efps-sign:' . $sign,
  646. 'x-efps-timestamp:' . date('YmdHis'),
  647. );
  648. curl_setopt($ch, CURLOPT_POST, 1);
  649. curl_setopt($ch, CURLOPT_URL, $url);
  650. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
  651. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  652. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过检查
  653. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 跳过检查
  654. //curl_setopt($ch, CURLOPT_HEADER, true);
  655. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  656. $response = curl_exec($ch);
  657. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  658. return array($httpCode, $response);
  659. }
  660. /**
  661. * 签名
  662. * @param $data
  663. * @return string
  664. */
  665. protected function YPLsign($data)
  666. {
  667. $certs = array();
  668. if (env("app.CUR_SYS_PARAMS") == 1) {
  669. //其中password为你的证书密码
  670. openssl_pkcs12_read(file_get_contents('/Users/sunriseos/Documents/www/wwwroot/cert/ypl/user-rsa.pfx'), $certs, 'zy2033.');
  671. } else {
  672. openssl_pkcs12_read(file_get_contents('/www/wwwroot/cert/ypl/user-rsa.pfx'), $certs, 'zy2033.'); //其中password为你的证书密码
  673. }
  674. ($certs) or die('您使用的私钥格式错误,请检查RSA私钥配置');
  675. openssl_sign($data, $sign, $certs['pkey'], OPENSSL_ALGO_SHA256);
  676. $sign = base64_encode($sign);
  677. return $sign;
  678. }
  679. /**
  680. * 费用配置
  681. * @param int $uid
  682. * @param array $data
  683. * @param int $type
  684. * @return array
  685. */
  686. public function _payConf(int $uid, array $data, int $type = 1)
  687. {
  688. $body = $total_amount = $remarks = '';
  689. switch ($data['order_type']) {
  690. case 1: // 充值
  691. $body = '充值';
  692. $total_amount = $data['money'];
  693. break;
  694. case 2: // 实名认证
  695. $total_amount = Db::name('user_data')->where('uid', $uid)->value('rz_money');
  696. $body = '实名认证费用';
  697. break;
  698. case 3: // 开通会员
  699. $vip_money = env('app.VIP_MONEY', 38);
  700. if (!$vip_money > 0) {
  701. throw new Exception('会员配置不存在');
  702. }
  703. $body = '开通会员';
  704. $total_amount = $vip_money;
  705. $remarks = $data['order_id'];
  706. break;
  707. case 4: //购买商品
  708. $order_sn = $data['order_id'];
  709. $checkingOrder = Order::checkingOrder($order_sn, 0, $uid);
  710. if (!$checkingOrder) {
  711. throw new Exception('校验订单失败');
  712. }
  713. if ($checkingOrder['flag'] !== 200) {
  714. throw new Exception($checkingOrder['msg']);
  715. }
  716. $body = '购买商品';
  717. $total_amount = $checkingOrder['orderPayment'];
  718. $remarks = $order_sn;
  719. //更改订单支付状态为线下支付待审核状态
  720. if ($data['channel'] == 4 && $data['order_type'] == 4) {
  721. Order::where('order_sn', 'in', $order_sn)->save(['pay_type' => 4, 'status' => 4]);
  722. }
  723. break;
  724. case 5: //余额充值
  725. {
  726. if (intval($data['money']) < 0) {
  727. sr_throw('金额填写错误,请填写整数');
  728. }
  729. if (!str_is_int($data['money'])) {
  730. sr_throw('充值金额有误,请输入正整数');
  731. }
  732. if ($data['money'] > 10000 || $data['money'] < 20) {
  733. sr_throw('请输入20到10000之间金额充值');
  734. }
  735. if ($data['channel'] == 19) {
  736. $usdt_price = Db::name('system_config')->where('name', 'usdt_price')->where('group', 'usdt_price')->value('value');
  737. }
  738. $charge_sn = createdRechargeOrderSn();
  739. Db::name('recharge_order')->insertGetId([
  740. 'recharge_sn' => $charge_sn,
  741. 'payment' => $data['money'],
  742. 'total_price' => $data['money'],
  743. 'usdt_money' => ($data['channel'] == 19 ? ceil($data['money'] / $usdt_price * 100) / 100 : 0),
  744. 'user_id' => $uid,
  745. 'pay_type' => $data['channel'],
  746. 'status' => 1,
  747. 'expires_time' => sr_getcurtime(time() + 0.5 * 3600),
  748. 'created_time' => sr_getcurtime(time())
  749. ]);
  750. $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');
  751. if ($count > 20) {
  752. sr_throw('未支付订单过多请2小时后在试');
  753. }
  754. $body = '用户充值';
  755. $total_amount = $data['money'];
  756. $remarks = $charge_sn;
  757. }
  758. break;
  759. case 6:
  760. {
  761. $money = env('boxsetting.SERVICES_STORE_OPEN_PRICE');
  762. $charge_sn = createdRechargeOrderSn();
  763. Db::name('services_order')->insertGetId([
  764. 'recharge_sn' => $charge_sn,
  765. 'payment' => $money,
  766. 'total_price' => $money,
  767. 'usdt_money' => 0,
  768. 'user_id' => $uid,
  769. 'pay_type' => $data['channel'],
  770. 'status' => 1,
  771. 'expires_time' => sr_getcurtime(time() + 0.5 * 3600),
  772. 'created_time' => sr_getcurtime(time())
  773. ]);
  774. $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');
  775. if ($count > 20) {
  776. sr_throw('未支付订单过多请稍后在试');
  777. }
  778. $body = '用户购买服务商服务';
  779. $total_amount = $money;
  780. $remarks = $charge_sn;
  781. }
  782. break;
  783. }
  784. if (!$body || !$total_amount || $total_amount <= 0)
  785. throw new Exception('配置错误');
  786. 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'] : ''];
  787. }
  788. /**
  789. * @param $uid
  790. * @param $params
  791. * @return \think\Response
  792. * @throws Exception
  793. * @throws \think\db\exception\DataNotFoundException
  794. * @throws \think\db\exception\DbException
  795. * @throws \think\db\exception\ModelNotFoundException
  796. */
  797. public function getPayInfoSQZ($uid, $params)
  798. {
  799. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  800. $sign_info = Db::name('user_bank_sign')->where('uid', $uid)->where('id', $params['sign_id'])->find();
  801. if (!$sign_info) {
  802. sr_throw('参数错误');
  803. }
  804. $order_id = '';
  805. if ($order_type == 4) {
  806. $order_id = $params['order_id'];
  807. }
  808. if ($order_type == 5) {
  809. $order_id = $remarks;
  810. }
  811. if ($order_type == 6) {
  812. // 如果是购买服务商订单 order_id 就是 services_order 里面的order_id
  813. $order_id = $remarks;
  814. }
  815. $out_trade_no = 'SY' . $order_id . mt_rand(1, 10000);
  816. // PAYBACK_URL
  817. $pay_success_backurl = env('PAYSQZ.PAYBACK_URL');
  818. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  819. // 这是测试 线要干掉
  820. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  821. }
  822. $parterid = env('PAYSQZ.PARTER');
  823. $params = [
  824. 'parter' => $parterid,
  825. 'type' => 1000,
  826. 'value' => $total_amount,
  827. 'orderid' => $out_trade_no,
  828. 'callbackurl' => $pay_success_backurl,
  829. 'payerIp' => request()->ip(),
  830. 'userno' => $sign_info['userno']
  831. ];
  832. $params['sign'] = md5('parter=' . $parterid . '&type=' . '1000' . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY'));
  833. $res = _curlrequest('http://pay.xindonglife.com/chargebank.aspx', $params, 'post');
  834. $res = json_decode($res);
  835. if (isset($res->code) && $res->code == 'SUCCESS') {
  836. $insert = [
  837. 'total_fee' => $total_amount,
  838. 'trade_type' => $trade_type,
  839. 'body' => $body,
  840. 'state' => 7,
  841. 'out_trade_no' => $out_trade_no,
  842. 'pay_way' => $pay_way,
  843. 'remarks' => $remarks,
  844. 'order_type' => $order_type,
  845. 'uid' => $uid,
  846. 'voucher_img' => $voucher_img,
  847. 'out_trade_no1' => $res->orderid,
  848. 'hy_token_id' => $res->hy_token_id
  849. ];
  850. Db::name('payment')->insert($insert);
  851. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySYL' => ['orderid' => $res->orderid, 'mobile' => $sign_info['phone']]]]);
  852. } else {
  853. sr_log('error' . json_encode($res));
  854. }
  855. }
  856. /**
  857. * 石区长-支付宝
  858. * @param $uid
  859. * @param $params
  860. * @return \think\Response
  861. * @throws Exception
  862. */
  863. public function getPayInfoSQZAlipay($uid, $params)
  864. {
  865. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  866. $order_id = '';
  867. if ($order_type == 4) {
  868. $order_id = $params['order_id'];
  869. }
  870. if ($order_type == 5) {
  871. $order_id = $remarks;
  872. }
  873. $out_trade_no = 'SA' . $order_id . mt_rand(1, 10000);
  874. // PAYBACK_URL
  875. $pay_success_backurl = env('PAYSQZ.PAYAliBACK_URL');
  876. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  877. // 这是测试 线要干掉
  878. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  879. }
  880. $parterid = env('PAYSQZ.PARTER');
  881. $params = [
  882. 'parter' => $parterid,
  883. 'type' => 1010,
  884. 'value' => $total_amount,
  885. 'orderid' => $out_trade_no,
  886. 'callbackurl' => $pay_success_backurl,
  887. 'payerIp' => request()->ip()
  888. ];
  889. // 提交确定支付
  890. sr_log('确认支付支付宝:' . json_encode($params));
  891. $params['sign'] = md5('parter=' . $parterid . '&type=' . '1010' . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY'));
  892. $url = 'http://pay.xindonglife.com/chargebank.aspx';
  893. $insert = [
  894. 'total_fee' => $total_amount,
  895. 'trade_type' => $trade_type,
  896. 'body' => $body,
  897. 'state' => 7,
  898. 'out_trade_no' => $out_trade_no,
  899. 'pay_way' => $pay_way,
  900. 'remarks' => $remarks,
  901. 'order_type' => $order_type,
  902. 'uid' => $uid,
  903. 'voucher_img' => $voucher_img,
  904. 'out_trade_no1' => '',
  905. 'hy_token_id' => ''
  906. ];
  907. Db::name('payment')->insert($insert);
  908. $pay_url = $url . '?' . http_build_query($params);
  909. sr_log('支付宝支付链接:' . $pay_url);
  910. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZAlipay' => ['pay_url' => $pay_url]]]);
  911. }
  912. /**
  913. * 石区长-微信支付
  914. * @param $uid
  915. * @param $params
  916. * @return \think\Response
  917. * @throws Exception
  918. */
  919. public function getPayInfoSQZWechat($uid, $params)
  920. {
  921. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  922. $order_id = '';
  923. if ($order_type == 4) {
  924. $order_id = $params['order_id'];
  925. }
  926. if ($order_type == 5) {
  927. $order_id = $remarks;
  928. }
  929. $out_trade_no = 'Sw' . $order_id . mt_rand(1, 10000);
  930. $pay_success_backurl = env('PAYSQZ.PAYWeixinBACK_URL');
  931. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  932. // 这是测试 线要干掉
  933. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  934. }
  935. $parterid = env('PAYSQZ.PARTER');
  936. $type = 1004;
  937. $params = [
  938. 'parter' => $parterid,
  939. 'type' => $type,
  940. 'value' => $total_amount,
  941. 'orderid' => $out_trade_no,
  942. 'callbackurl' => $pay_success_backurl,
  943. 'payerIp' => request()->ip()
  944. ];
  945. // 提交确定支付
  946. sr_log('确认支付:' . json_encode($params));
  947. $params['sign'] = md5('parter=' . $parterid . '&type=' . $type . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SIGNKEY'));
  948. $url = 'http://pay.xindonglife.com/chargebank.aspx';
  949. $insert = [
  950. 'total_fee' => $total_amount,
  951. 'trade_type' => $trade_type,
  952. 'body' => $body,
  953. 'state' => 7,
  954. 'out_trade_no' => $out_trade_no,
  955. 'pay_way' => $pay_way,
  956. 'remarks' => $remarks,
  957. 'order_type' => $order_type,
  958. 'uid' => $uid,
  959. 'voucher_img' => $voucher_img,
  960. 'out_trade_no1' => '',
  961. 'hy_token_id' => ''
  962. ];
  963. Db::name('payment')->insert($insert);
  964. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZ' => ['pay_url' => $url . '?' . http_build_query($params)]]]);
  965. }
  966. /**
  967. * @param $uid
  968. * @param $params
  969. * @return \think\Response
  970. * @throws Exception
  971. */
  972. public function getPayInfoSQZBankkuai($uid, $params)
  973. {
  974. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  975. $order_id = '';
  976. if ($order_type == 4) {
  977. $order_id = $params['order_id'];
  978. }
  979. if ($order_type == 5) {
  980. $order_id = $remarks;
  981. }
  982. $out_trade_no = 'SK' . $order_id . mt_rand(1, 10000);
  983. $pay_success_backurl = env('PAYSQZ.PAYKUAIJIEBACK_URL');
  984. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  985. // 这是测试 线要干掉
  986. $total_amount = floatval('0.' . mt_rand(1, 3) . mt_rand(1, 9));
  987. }
  988. $parterid = env('PAYSQZ.SXY_PARTER');
  989. $type = 967;
  990. $params = [
  991. 'parter' => $parterid,
  992. 'type' => $type,
  993. 'value' => $total_amount,
  994. 'orderid' => $out_trade_no,
  995. 'callbackurl' => $pay_success_backurl,
  996. 'payerIp' => request()->ip()
  997. ];
  998. // 提交确定支付
  999. sr_log('确认支付:' . json_encode($params));
  1000. $params['sign'] = md5('parter=' . $parterid . '&type=' . $type . '&value=' . $total_amount . '&orderid=' . $out_trade_no . '&callbackurl=' . $pay_success_backurl . env('PAYSQZ.SXY_SIGNKEY'));
  1001. $url = 'http://pay.xindonglife.com/chargebank.aspx';
  1002. $insert = [
  1003. 'total_fee' => $total_amount,
  1004. 'trade_type' => $trade_type,
  1005. 'body' => $body,
  1006. 'state' => 7,
  1007. 'out_trade_no' => $out_trade_no,
  1008. 'pay_way' => $pay_way,
  1009. 'remarks' => $remarks,
  1010. 'order_type' => $order_type,
  1011. 'uid' => $uid,
  1012. 'voucher_img' => $voucher_img,
  1013. 'out_trade_no1' => '',
  1014. 'hy_token_id' => ''
  1015. ];
  1016. Db::name('payment')->insert($insert);
  1017. return api_succ_return(['msg' => '成功', 'data' => ['thirdpaySQZ' => ['pay_url' => $url . '?' . http_build_query($params)]]]);
  1018. }
  1019. /**
  1020. * 银盛快捷无卡
  1021. * @param $uid
  1022. * @param $params
  1023. * @return \think\Response
  1024. * @throws Exception
  1025. * @throws \think\db\exception\DataNotFoundException
  1026. * @throws \think\db\exception\DbException
  1027. * @throws \think\db\exception\ModelNotFoundException
  1028. */
  1029. public function getPayInfoYSwk($uid, $params)
  1030. {
  1031. if (empty($params['cer_no']) || empty($params['cer_name'] || empty($params['bank_id']) || empty($params['bank_type']) || empty($params['bank_no']) || empty($params['mobile']))) {
  1032. return api_error_return("参数错误");
  1033. }
  1034. if ($params['bank_type'] == 2) {
  1035. if (empty($params['card_expr_time']) || empty($params['security_code'])) {
  1036. return api_error_return('信用卡类型必须填写信用卡上面的三位安全码跟过期时间');
  1037. }
  1038. }
  1039. $bank_info = Db::name('ys_banklist')->where('id', $params['bank_id'])->find();
  1040. if (!$bank_info) {
  1041. return api_error_return('参数错误');
  1042. }
  1043. $buy_mobilee = $params['mobile'];
  1044. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  1045. $interface_url = 'https://openapi.ysepay.com/gateway.do'; //正式
  1046. $order_id = '';
  1047. if ($order_type == 4) {
  1048. $order_id = $params['order_id'];
  1049. }
  1050. if ($order_type == 5) {
  1051. $order_id = $remarks;
  1052. }
  1053. $out_trade_no = $order_id . '_yswk' . mt_rand(1, 10000);
  1054. // PAYBACK_URL
  1055. $pay_success_backurl = env('PAYSQZ.PAYKUAIJIEBACK_URL');
  1056. // $total_amount = 1;
  1057. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  1058. // 这是测试 线要干掉
  1059. $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9));
  1060. }
  1061. $parterid = env('ZLYS.PARTER_ID');
  1062. $cur_time = sr_getcurtime(time());
  1063. $biz_content = array();
  1064. $biz_content['out_trade_no'] = $out_trade_no;
  1065. $biz_content['shopdate'] = sr_getcurtime(time(), 'Ymd');
  1066. $biz_content['subject'] = '购买商品';
  1067. // $biz_content['total_amount'] = $total_amount;
  1068. $biz_content['total_amount'] = $total_amount;
  1069. $biz_content['timeout_express'] = '1h';
  1070. $biz_content['currency'] = 'CNY';
  1071. $biz_content['business_code'] = '3010002';
  1072. $biz_content['seller_id'] = $parterid;
  1073. $biz_content['bank_type'] = $bank_info['bank_value'];
  1074. $biz_content['buyer_name'] = $params['cer_name'];
  1075. $biz_content['buyer_card_number'] = $params['bank_no'];
  1076. $biz_content['buyer_mobile'] = $params['mobile'];
  1077. $number = trim($this->ECBEncrypt($params['cer_no'], 'Scf10981'));
  1078. // 银行卡类型 debit 借记卡 credit信用卡
  1079. $biz_content['support_card_type'] = intval($params['bank_type']) == 1 ? 'debit' : 'credit';
  1080. if ($params['bank_type'] == 2) {
  1081. $biz_content['cardCvn2'] = $this->ECBEncrypt($params['security_code'], 'Scf10981');
  1082. $biz_content['cardExprDt'] = $this->ECBEncrypt($params['card_expr_time'], 'Scf10981');
  1083. }
  1084. $biz_content['bank_name'] = $bank_info['bank_name'];
  1085. $biz_content['pyerIDNo'] = $number;
  1086. $biz_content['pyerIDTp'] = $this->ECBEncrypt('01', 'Scf10981');;
  1087. $biz_content['bank_account_type'] = 'personal';
  1088. $params = [
  1089. 'method' => 'ysepay.online.fastpay',
  1090. 'partner_id' => $parterid,
  1091. 'timestamp' => $cur_time,
  1092. 'charset' => 'UTF-8',
  1093. 'sign_type' => 'RSA',
  1094. 'notify_url' => env('ZLYS.PAYBACK_URL'),
  1095. 'version' => '3.4',
  1096. 'biz_content' => json_encode($biz_content, JSON_UNESCAPED_UNICODE)
  1097. ];
  1098. ksort($params);
  1099. $params['sign'] = $this->sign($params);
  1100. // 提交确定支付
  1101. sr_log('确认支付:' . json_encode($params));
  1102. $result = curlPost($interface_url, $params);
  1103. sr_log('result:' . $result);
  1104. $res = json_decode($result);
  1105. 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') {
  1106. $trade_no = $res->ysepay_online_fastpay_response->trade_no;
  1107. $insert = [
  1108. 'total_fee' => $total_amount,
  1109. 'trade_type' => $trade_type,
  1110. 'body' => $body,
  1111. 'state' => 7,
  1112. 'out_trade_no' => $out_trade_no,
  1113. 'pay_way' => $pay_way,
  1114. 'remarks' => $remarks,
  1115. 'order_type' => $order_type,
  1116. 'uid' => $uid,
  1117. 'voucher_img' => $voucher_img,
  1118. 'out_trade_no1' => '',
  1119. 'hy_token_id' => '',
  1120. 'buyer_mobile' => $buy_mobilee,
  1121. 'trade_no' => $trade_no
  1122. ];
  1123. Db::name('payment')->insert($insert);
  1124. return api_succ_return(['msg' => '成功', 'data' => ['thirdpayYS' => ['trade_no' => $trade_no]]]);
  1125. } else {
  1126. if (isset($res->ysepay_online_fastpay_response->sub_msg)) {
  1127. return api_error_return($res->ysepay_online_fastpay_response->sub_msg);
  1128. } else {
  1129. return api_error_return('支付错误,请联系客服');
  1130. }
  1131. }
  1132. return api_error_return('支付错误,请联系客服1');
  1133. }
  1134. /**
  1135. * 电科支付宝支付信息
  1136. * @param $uid
  1137. * @param $params
  1138. * @return \think\Response
  1139. * @throws Exception
  1140. */
  1141. public function getPayInfoDiankeZfb($uid, $payData)
  1142. {
  1143. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $payData);
  1144. // 接口地址
  1145. $apiUrl = env('PAYDK.DKPAY_API_URL','http://1.14.197.47/proxy/pay/unifiedorder');
  1146. $date = date('Y-m-d H:i:s');
  1147. $out_trade_no = createdOrderSn();
  1148. $cacheKey = "caches:payment:dkpay:otn_{$out_trade_no}:{$uid}_{$remarks}_";
  1149. RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400);
  1150. // 测试金额
  1151. if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
  1152. $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9));
  1153. }
  1154. if ($total_amount > 15000) {
  1155. $loData = ['payData'=> $payData,'error'=>'大额不能使用支付宝支付', 'date'=>$date];
  1156. RedisCache::set($cacheKey.'error', $loData, 2*86400);
  1157. sr_throw('大额不能使用支付宝支付');
  1158. }
  1159. $params = [
  1160. 'appId' => 'dianke',
  1161. 'version' => '1.0',
  1162. 'nonceStr' => nonce_str(15),
  1163. 'orderId' => $out_trade_no,
  1164. 'amount' => intval($total_amount * 100),
  1165. 'payChannel' => 'ALP',
  1166. 'goodsName' => $body? $body : '牛仔裤',
  1167. 'goodsDesc' => $body? $body : '牛仔裤',
  1168. 'clientIp' => get_client_ip(),
  1169. 'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_ZFB_NEWURL'),
  1170. 'tradeType' => 'QRCODE'
  1171. ];
  1172. ksort($params);
  1173. $params['sign'] = $this->diankesign($params);
  1174. // 提交确定支付请求接口
  1175. $loData = ['url'=>$apiUrl,'payData'=> $payData,'params'=> $params, 'date'=>$date];
  1176. RedisCache::set($cacheKey.'request', $loData, 2*86400);
  1177. $result = curlPost($apiUrl, $params);
  1178. $result = $result? json_decode($result, true) : [];
  1179. $payUrl = isset($result['data'])? $result['data'] : '';
  1180. $loData['result'] = $result;
  1181. RedisCache::set($cacheKey.'result', $loData, 2*86400);
  1182. if ($payUrl) {
  1183. $payment = [
  1184. 'total_fee' => $total_amount,
  1185. 'trade_type' => $trade_type,
  1186. 'body' => $body,
  1187. 'state' => 7,
  1188. 'out_trade_no' => $out_trade_no,
  1189. 'pay_way' => $pay_way,
  1190. 'remarks' => $remarks,
  1191. 'order_type' => $order_type,
  1192. 'uid' => $uid,
  1193. 'voucher_img' => $voucher_img,
  1194. 'out_trade_no1' => '',
  1195. 'hy_token_id' => ''
  1196. ];
  1197. Db::name('payment')->insert($payment);
  1198. return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]);
  1199. } else {
  1200. return api_error_return('支付错误,请联系客服');
  1201. }
  1202. }
  1203. /**
  1204. * 银盛-第三方快捷支付
  1205. * @param $trade_no
  1206. * @param $sms_code
  1207. * @return \think\Response
  1208. * @throws Exception
  1209. * @throws \think\db\exception\DataNotFoundException
  1210. * @throws \think\db\exception\DbException
  1211. * @throws \think\db\exception\ModelNotFoundException
  1212. */
  1213. public function kjPayWithCode($trade_no, $sms_code)
  1214. {
  1215. $payment_info = Db::name('payment')->where('trade_no', $trade_no)->find();
  1216. if (!$payment_info) {
  1217. sr_throw('支付订单错误');
  1218. }
  1219. $out_trade_no = $payment_info['out_trade_no'];
  1220. $interface_url = 'https://openapi.ysepay.com/gateway.do'; //正式
  1221. $parterid = env('ZLYS.PARTER_ID');
  1222. $cur_time = sr_getcurtime(time());
  1223. $biz_content = array();
  1224. $biz_content['out_trade_no'] = $out_trade_no;
  1225. $biz_content['buyer_mobile'] = $payment_info['buyer_mobile'];
  1226. $biz_content['mobile_verify_code'] = $sms_code;
  1227. $params = [
  1228. 'method' => 'ysepay.online.fastpay.authorize',
  1229. 'partner_id' => $parterid,
  1230. 'timestamp' => $cur_time,
  1231. 'charset' => 'UTF-8',
  1232. 'sign_type' => 'RSA',
  1233. 'notify_url' => env('ZLYS.PAYBACK_URL'),
  1234. 'version' => '3.0',
  1235. 'biz_content' => json_encode($biz_content, JSON_UNESCAPED_UNICODE)
  1236. ];
  1237. ksort($params);
  1238. $params['sign'] = $this->sign($params);
  1239. // 提交确定支付
  1240. sr_log('确认支付提交:' . json_encode($params));
  1241. $result = curlPost($interface_url, $params);
  1242. sr_log('result:' . $result);
  1243. $res = json_decode($result);
  1244. if (isset($res->ysepay_online_fastpay_authorize_response->code) && intval($res->ysepay_online_fastpay_authorize_response->code) == 10000 && isset($res->ysepay_online_fastpay_authorize_response->msg) && intval($res->ysepay_online_fastpay_authorize_response->msg) == 'Success') {
  1245. return api_succ_return('成功');
  1246. } else {
  1247. if (isset($res->ysepay_online_fastpay_authorize_response->sub_msg)) {
  1248. return api_error_return($res->ysepay_online_fastpay_authorize_response->sub_msg);
  1249. } else {
  1250. return api_error_return('支付错误,请联系客服');
  1251. }
  1252. }
  1253. }
  1254. /**
  1255. * DES加密方法
  1256. * @param $data 传入需要加密的证件号码
  1257. * @param $key key为商户号前八位.不足八位的需在商户号前补空格
  1258. * @return string 返回加密后的字符串
  1259. */
  1260. function ECBEncrypt($data, $key)
  1261. {
  1262. $encrypted = openssl_encrypt($data, 'DES-ECB', $key, 1);
  1263. return base64_encode($encrypted);
  1264. }
  1265. /**
  1266. * DES解密方法
  1267. * @param $data 传入需要解密的字符串
  1268. * @param $key key为商户号前八位.不足八位的需在商户号前补空格
  1269. * @return string 返回解密后的证件号码
  1270. */
  1271. function doECBDecrypt($data, $key)
  1272. {
  1273. $encrypted = base64_decode($data);
  1274. $decrypted = openssl_decrypt($encrypted, 'DES-ECB', $key, 1);
  1275. return $decrypted;
  1276. }
  1277. /**
  1278. * 签名加密
  1279. * @param input data
  1280. * @return success
  1281. * @return check
  1282. * @return msg
  1283. */
  1284. public function sign_encrypt($input)
  1285. {
  1286. $return = [
  1287. 'success' => 0,
  1288. 'msg' => '',
  1289. 'check' => ''
  1290. ];
  1291. $pkcs12 = file_get_contents(env('ZLYS.PFX_PATH')); //私钥
  1292. if (openssl_pkcs12_read($pkcs12, $certs, env('ZLYS.PSSSWORD'))) {
  1293. $privateKey = $certs['pkey'];
  1294. $publicKey = $certs['cert'];
  1295. $signedMsg = "";
  1296. if (openssl_sign($input['data'], $signedMsg, $privateKey, OPENSSL_ALGO_SHA1)) {
  1297. $return['success'] = 1;
  1298. $return['check'] = base64_encode($signedMsg);
  1299. $return['msg'] = base64_encode($input['data']);
  1300. }
  1301. }
  1302. return $return;
  1303. }
  1304. /**
  1305. * 签名
  1306. * @param $data
  1307. * @return string
  1308. */
  1309. public function sign($data)
  1310. {
  1311. ksort($data);
  1312. $signStr = "";
  1313. foreach ($data as $key => $val) {
  1314. $signStr .= $key . '=' . $val . '&';
  1315. }
  1316. $signStr = trim($signStr, '&');
  1317. $sign = $this->sign_encrypt(array('data' => $signStr));
  1318. return trim($sign['check']);
  1319. }
  1320. /**
  1321. * 签名
  1322. * @param $data
  1323. * @return string
  1324. */
  1325. public function diankesign($data)
  1326. {
  1327. ksort($data);
  1328. $signStr = "";
  1329. foreach ($data as $key => $val) {
  1330. $signStr .= $key . '=' . $val . '&';
  1331. }
  1332. $stringSignTemp = $signStr . 'key=a05fd6fc1f924b74b83dfd519ce93c28';
  1333. $signtemp = \md5($stringSignTemp);
  1334. return strtoupper($signtemp);
  1335. }
  1336. /**
  1337. * 签名
  1338. * @param $data
  1339. * @return string
  1340. */
  1341. public function diankesigndf($data)
  1342. {
  1343. ksort($data);
  1344. $signStr = "";
  1345. foreach ($data as $key => $val) {
  1346. $signStr .= $key . '=' . $val . '&';
  1347. }
  1348. $stringSignTemp = $signStr . 'key=b91f3a72fe074e39a6add7382de813bc';
  1349. $signtemp = \md5($stringSignTemp);
  1350. return strtoupper($signtemp);
  1351. }
  1352. /**
  1353. * USDT
  1354. * @param $uid
  1355. * @param $params
  1356. * @return \think\Response
  1357. * @throws Exception
  1358. */
  1359. public function getPayInfoUsdt($uid, $params)
  1360. {
  1361. list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $params);
  1362. return api_succ_return('成功');
  1363. }
  1364. /**
  1365. * 签约银行卡
  1366. * @param $uid
  1367. * @param $post
  1368. * @return mixed
  1369. * @throws Exception
  1370. * @throws \think\db\exception\DataNotFoundException
  1371. * @throws \think\db\exception\DbException
  1372. * @throws \think\db\exception\ModelNotFoundException
  1373. */
  1374. public function userBankSign($uid, $post)
  1375. {
  1376. $pay_success_backurl = env('PAYSQZ.USER_SIGN_BANK');
  1377. $parterid = env('PAYSQZ.PARTER');
  1378. $phone = $post['phone'];
  1379. $bankCard = $post['bank_card'];
  1380. $name = $post['name'];
  1381. $idCard = $post['id_card'];
  1382. $orderId = creatBankSignOrderSn($uid);
  1383. if ($info = UserBankSignService::make()->checkHasSign($uid, $bankCard, 4)) {
  1384. UserBankSignModel::where('id', $info['id'])->save([
  1385. 'status' => 1,
  1386. 'signorder_id' => $orderId
  1387. ]);
  1388. } else {
  1389. UserBankSignModel::insert([
  1390. 'uid' => $uid,
  1391. 'phone' => $phone,
  1392. 'bank_card' => $bankCard,
  1393. 'name' => $name,
  1394. 'id_card' => $idCard,
  1395. 'create_time' => sr_getcurtime(time()),
  1396. 'signorder_id' => $orderId
  1397. ]);
  1398. }
  1399. // 签约参数
  1400. $param = [
  1401. 'parter' => $parterid,
  1402. 'userid' => $uid,
  1403. 'phone' => $phone,
  1404. 'bankCard' => $bankCard,
  1405. 'name' => $name,
  1406. 'idCard' => $idCard,
  1407. 'orderid' => $orderId,
  1408. 'callBack' => $pay_success_backurl
  1409. ];
  1410. $keystring = 'parter=' . $parterid . '&userid=' . $uid . '&phone=' . $phone . '&bankCard=' . $bankCard . '&name=' . $name . '&idCard=' . $idCard . '&orderid=' . $orderId . env('PAYSQZ.SIGNKEY');
  1411. $param['sign'] = md5($keystring);
  1412. $cacheKey = "caches:userBankSign:user_{$uid}:{$bankCard}_";
  1413. RedisCache::set($cacheKey.'param', $param, 7200);
  1414. $res = _curlrequest('http://pay.xindonglife.com/PageSign.aspx', $param, 'post');
  1415. RedisCache::set($cacheKey.'result', ['param'=> $param,'result'=>$res,'date'=>date('Y-m-d H:i:s')], 7200);
  1416. $result = json_decode($res);
  1417. if (isset($result->code) && $result->code == 'SUCCESS') {
  1418. return $result->sign_url;
  1419. } else {
  1420. if (is_string($res)) {
  1421. sr_throw($res);
  1422. } else {
  1423. sr_throw('请求失败,请稍后再试');
  1424. }
  1425. }
  1426. }
  1427. /**
  1428. * 解绑银行卡
  1429. * @param $uid
  1430. * @param $post
  1431. * @throws Exception
  1432. * @throws \think\db\exception\DataNotFoundException
  1433. * @throws \think\db\exception\DbException
  1434. * @throws \think\db\exception\ModelNotFoundException
  1435. */
  1436. public function userUnBankSign($uid, $post)
  1437. {
  1438. $parterid = env('PAYSQZ.PARTER');
  1439. $orderId = creatBankSignOrderSn($uid);
  1440. $recordId = isset($post['record_id'])? intval($post['record_id']) : 0;
  1441. if (!$recordId || !$bankInfo = UserBankSignService::make()->getCacheInfo($recordId, $uid)) {
  1442. sr_throw('参数错误');
  1443. }
  1444. $param = [
  1445. 'parter' => $parterid,
  1446. 'hy_auth_uid' => $bankInfo['userno'],
  1447. 'orderId' => $orderId
  1448. ];
  1449. $keystring = 'parter=' . $parterid . '&hy_auth_uid=' . $bankInfo['userno'] . env('PAYSQZ.SIGNKEY');
  1450. $param['sign'] = md5($keystring);
  1451. $cacheKey = "caches:userBankSign:{$uid}_{$recordId}_{$parterid}:";
  1452. RedisCache::set($cacheKey.'param', $param, 7200);
  1453. $res = _curlrequest('http://pay.xindonglife.com/CardUnbinding.aspx', $param, 'post');
  1454. RedisCache::set($cacheKey.'result', ['param'=> $param,'result'=> $res,'date'=>date('Y-m-d H:i:s')], 7200);
  1455. $res = json_decode($res);
  1456. if (isset($res->code) && $res->code == 'SUCCESS') {
  1457. RedisCache::keyDel("caches:userBankSign*");
  1458. UserBankSignModel::where('id', $post['record_id'])->save(['signorder_u_id' => $orderId, 'status' => 4]);
  1459. } else {
  1460. RedisCache::set($cacheKey.'back', ['error'=>'解绑失败','param'=> $param,'result'=> $res,'date'=>date('Y-m-d H:i:s')], 7200);
  1461. sr_throw('解绑失败');
  1462. }
  1463. }
  1464. /**
  1465. * 石学长 银联支付
  1466. * @param $uid
  1467. * @param $params
  1468. * @throws Exception
  1469. * @throws \think\db\exception\DataNotFoundException
  1470. * @throws \think\db\exception\DbException
  1471. * @throws \think\db\exception\ModelNotFoundException
  1472. */
  1473. public function sylSurePay($uid, $params)
  1474. {
  1475. if (empty($params['sms_code'])) {
  1476. sr_throw('参数错误');
  1477. }
  1478. $payment_info = Db::name('payment')->where('out_trade_no1', $params['order_id'])->where('state', 7)->where('uid', $uid)->find();
  1479. if (!$payment_info) {
  1480. sr_throw('参数错误或者订单错误');
  1481. }
  1482. $parterid = env('PAYSQZ.PARTER');
  1483. $order_id = creatBankSignOrderSn($uid);
  1484. $out_trade_no1 = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
  1485. $param = [
  1486. 'parter' => $parterid,
  1487. 'hy_token_id' => $payment_info['hy_token_id'],
  1488. 'verify_code' => $params['sms_code'],
  1489. 'orderId' => $out_trade_no1
  1490. ];
  1491. $keystring = 'parter=' . $parterid . '&hy_token_id=' . $payment_info['hy_token_id'] . '&verify_code=' . $params['sms_code'] . env('PAYSQZ.SIGNKEY');
  1492. $param['sign'] = md5($keystring);
  1493. $res = _curlrequest('http://pay.xindonglife.com/payMentConfirm.aspx', $param, 'post');
  1494. $res = json_decode($res);
  1495. if (isset($res->code) && $res->code == 'SUCCESS') {
  1496. Db::name('payment')->where('id', $payment_info['id'])->save(['hy_bill_no' => $res->hy_bill_no, 'syl_sureorderid' => $out_trade_no1]);
  1497. } else {
  1498. if (isset($res->message)) {
  1499. sr_throw($res->message);
  1500. }
  1501. // {"id":1,"code":"Fail","message":"\u77ed\u4fe1\u9a8c\u8bc1\u7801\u5df2\u8fc7\u671f"}
  1502. // sr_log('确认失败:'.json_encode($res));
  1503. }
  1504. }
  1505. /**
  1506. * pay_money 支付订单的金额
  1507. * @param $out_trade_no
  1508. * @param $pay_money
  1509. * @param $pay_type
  1510. * @param $content
  1511. * @throws Exception
  1512. * @throws \think\db\exception\DataNotFoundException
  1513. * @throws \think\db\exception\DbException
  1514. * @throws \think\db\exception\ModelNotFoundException
  1515. */
  1516. public function payBack($out_trade_no, $pay_money, $pay_type, $content, $cacheKey='')
  1517. {
  1518. $date = date('Y-m-d H:i:s');
  1519. $shopordermodel = new ShopOrderModel();
  1520. $services_ordermodel = new ServicesOrderModel();
  1521. $params = $content? json_encode($content, true):[];
  1522. $cacheKey = $cacheKey? $cacheKey : "caches:payment:callBack:{$out_trade_no}";
  1523. RedisCache::set($cacheKey.'_catch', ['params'=>$params,'date'=> $date], 7200);
  1524. // 验证支付请求信息
  1525. $payInfo = PaymentModel::where('out_trade_no', $out_trade_no)->where('state', 7)->find();
  1526. $payUid = isset($payInfo['uid'])? $payInfo['uid']:0;
  1527. if (!$payInfo || $payUid<=0) {
  1528. $logData = ['params'=>$params,'msg'=>"单号{$out_trade_no}已经回调支付,或支付信息不存在",'date'=> $date];
  1529. RedisCache::set($cacheKey.'_error', $logData, 7200);
  1530. sr_throw('outtradeno已经回调支付:' . $out_trade_no);
  1531. }
  1532. $nowTime = date('Y-m-d H:i:s', time());
  1533. $userInfo = UserService::make()->getCacheInfo($payUid);
  1534. if ($payInfo['order_type'] == 6) {
  1535. $date = sr_getcurtime(time(), 'Y-m-d');
  1536. $expire_day = date('Y-m-d', strtotime("$date +1 month"));
  1537. $payInfo->save(['state' => 6, 'pay_at' => $nowTime]);
  1538. $services_orderinfo = $services_ordermodel->where('recharge_sn', $payInfo['remarks'])->find();
  1539. if ($services_orderinfo) {
  1540. $services_orderinfo->save(['status' => 2, 'pay_type' => $pay_type, 'updated_time' => $nowTime]);
  1541. }
  1542. Db::name('user')->where('id', $services_orderinfo['user_id'])->save([
  1543. 'store_type' => 1,
  1544. 'store_expire_time' => $expire_day
  1545. ]);
  1546. } elseif ($payInfo['order_type'] == 4) {
  1547. $nowTime = date('Y-m-d H:i:s', time());
  1548. $payInfo->save(['state' => 6, 'pay_at' => $nowTime]);
  1549. $order_info = $shopordermodel->where('order_sn', $payInfo['remarks'])->find();
  1550. Db::name('user')->whereIn('id', $userInfo['path'])->inc('total_team_income', $payInfo['total_fee'])->update();
  1551. Db::name('user')->whereIn('id', $userInfo['id'])->inc('total_team_income', $payInfo['total_fee'])->update();
  1552. Db::name('user')->where('id', $userInfo['id'])->inc('total_income', $payInfo['total_fee'])->update();
  1553. $order_info->save(['status' => 1, 'pay_type' => $pay_type, 'updated_time' => $nowTime]);
  1554. // 增加销量
  1555. $orderGoods = OrderGoods::where(['order_id' => $order_info['order_id']])->select()->toArray();
  1556. foreach ($orderGoods as $k => $v) {
  1557. ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update();
  1558. }
  1559. $uid = $payInfo['uid'];
  1560. Db::name('thirdpay_back')->insert([
  1561. 'out_order_no' => $out_trade_no,
  1562. 'content' => $content,
  1563. 'create_time' => sr_getcurtime(time()),
  1564. 'type' => $pay_type,
  1565. 'uid' => $uid,
  1566. 'money' => $pay_money
  1567. ]);
  1568. // 赠送积分
  1569. edit_user_score(3, $uid, $order_info['rebate_score'], 0, $payInfo['id']);
  1570. }
  1571. }
  1572. /**
  1573. * ay_money 代付回调金额
  1574. * @param $out_trade_no
  1575. * @param $pay_money
  1576. * @param $params
  1577. * @param $content
  1578. * @throws \think\db\exception\DataNotFoundException
  1579. * @throws \think\db\exception\DbException
  1580. * @throws \think\db\exception\ModelNotFoundException
  1581. */
  1582. public function payDfBack($out_trade_no, $pay_money, $params, $content)
  1583. {
  1584. if (isset($params['status'])) {
  1585. $model = new WithDrawLogModel();
  1586. $info = $model->where('out_biz_no', $out_trade_no)->find();
  1587. if (!$info) {
  1588. return;
  1589. }
  1590. if ($info && $info['status'] == 4) {
  1591. if ($params['status'] == 1) {
  1592. // 代付成功
  1593. $info->save(['status' => 1]);
  1594. } else {
  1595. Db::startTrans();
  1596. try {
  1597. Db::startTrans();//开启事务
  1598. $info = $model->where('out_biz_no', $out_trade_no)->find();
  1599. $user_info = Db::name('user')->where('id', $info['uid'])->lock(true)->find();
  1600. $res = edit_user_money(10, $info['uid'], $info['apply_money']);
  1601. Db::name('action_liangb')->insert([
  1602. 'create_time' => sr_getcurtime(time()),
  1603. 'wd_id' => $out_trade_no
  1604. ]);
  1605. // 代付失败
  1606. $info->save(['zfb_error' => $content, 'status' => 3]);
  1607. Db::commit();
  1608. } catch (\Exception $e) {
  1609. Db::rollback();
  1610. sr_log('代付回调报错');
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. /**
  1617. * @param $uid
  1618. * @param $pay_info
  1619. * @param $yeji
  1620. * @throws \think\db\exception\DataNotFoundException
  1621. * @throws \think\db\exception\DbException
  1622. * @throws \think\db\exception\ModelNotFoundException
  1623. */
  1624. public function scaleAgentMoney($uid, $pay_info, $yeji)
  1625. {
  1626. $is_privince_get = false;
  1627. $is_city_get = false;
  1628. $money = intval($pay_info['total_fee'] / 100) * 100;
  1629. $user_info = Db::name('user')->where('id', $uid)->find();
  1630. $path = $user_info['path'];
  1631. // sr_log('path:'.$path);
  1632. $arr = explode(',', $path);
  1633. $arr = array_reverse($arr);
  1634. $ids = $arr;
  1635. $ids = implode(',', $ids);
  1636. $order = 'field(id,' . $ids . ')';
  1637. $users = Db::name('user')->where('id', 'in', $arr)->field('id,level,agent_type')->order(Db::raw($order))->select()->toArray();
  1638. foreach ($users as $key => $val) {
  1639. if ($val['agent_type'] == 1) {
  1640. if (!$is_privince_get) {
  1641. if ($is_city_get) {
  1642. edit_user_money(17, $val['id'], $money * 0.5 / 100, 0, $pay_info['remarks']);
  1643. } else {
  1644. edit_user_money(17, $val['id'], $money / 100, 0, $pay_info['remarks']);
  1645. }
  1646. $is_privince_get = true;
  1647. }
  1648. }
  1649. if ($val['agent_type'] == 2) {
  1650. if (!$is_privince_get) {
  1651. edit_user_money(18, $val['id'], $money * 0.5 / 100, 0, $pay_info['remarks']);
  1652. }
  1653. $is_city_get = true;
  1654. }
  1655. }
  1656. }
  1657. /**
  1658. * pay_money 余额支付订单的金额
  1659. * @param $order_sn
  1660. * @param $pay_type
  1661. * @param $content
  1662. * @throws \think\db\exception\DataNotFoundException
  1663. * @throws \think\db\exception\DbException
  1664. * @throws \think\db\exception\ModelNotFoundException
  1665. */
  1666. public function payBalanceDown($order_sn, $pay_type, $content)
  1667. {
  1668. $paymodel = new PaymentModel();
  1669. $shopordermodel = new ShopOrderModel();
  1670. $usermodel = new UserModel();
  1671. $order_info = $shopordermodel->where('order_sn', $order_sn)->find();
  1672. $nowTime = date('Y-m-d H:i:s', time());
  1673. $user_info = $usermodel->where('id', $order_info['user_id'])->find();
  1674. $order_info->save(['status' => 1, 'pay_type' => $pay_type, 'updated_time' => $nowTime]);
  1675. // 增加销量
  1676. $orderGoods = OrderGoods::where(['order_id' => $order_info['order_id']])->select()->toArray();
  1677. foreach ($orderGoods as $k => $v) {
  1678. ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update();
  1679. }
  1680. $uid = $order_info['user_id'];
  1681. Db::name('thirdpay_back')->insert([
  1682. 'out_order_no' => '',
  1683. 'content' => $content,
  1684. 'create_time' => sr_getcurtime(time()),
  1685. 'type' => $pay_type,
  1686. 'uid' => $uid,
  1687. 'money' => $order_info['payment']
  1688. ]);
  1689. // 给用户添加业绩
  1690. $pay_info = $paymodel->where('remarks', $order_sn)->where('state', 6)->find();
  1691. // 赠送积分
  1692. edit_user_score(1, $uid, $order_info['rebate_score']);
  1693. $this->update_user_yeji($uid, $user_info, $order_info, $pay_info);
  1694. }
  1695. /**
  1696. * @param $uid
  1697. * @param $user_info
  1698. * @param $order_info
  1699. * @param $pay_info
  1700. * @throws \think\db\exception\DataNotFoundException
  1701. * @throws \think\db\exception\DbException
  1702. * @throws \think\db\exception\ModelNotFoundException
  1703. */
  1704. public function update_user_yeji($uid, $user_info, $order_info, $pay_info)
  1705. {
  1706. // 计算用户的yeji
  1707. $yeji = 0;
  1708. // 根据所送的积分算业绩
  1709. if ($user_info['performance_me'] < 10000) {
  1710. if (($user_info['performance_me'] + $order_info['rebate_score']) > 10000) {
  1711. $yeji = 10000 - $user_info['performance_me'];
  1712. incUserPerformance($uid, $yeji);
  1713. } else {
  1714. $yeji = $order_info['rebate_score'];
  1715. incUserPerformance($uid, $yeji);
  1716. }
  1717. }
  1718. if ($yeji > 0) {
  1719. // 如果增加的业绩大于0 计算省代跟市代
  1720. //
  1721. $this->scaleAgentMoney($order_info['user_id'], $pay_info, $yeji);
  1722. }
  1723. }
  1724. /**
  1725. * 手续费
  1726. * @param $uid
  1727. * @param $pay_info
  1728. * @param $nowTime
  1729. * @param int $type
  1730. * @return false
  1731. */
  1732. public function update_user_free($uid, $pay_info, $nowTime, $type = 1){
  1733. // return false;
  1734. }
  1735. }