ThirdPayServices.php 85 KB

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