PayNotify.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. <?php
  2. /**
  3. * 支付的服务器异步通知控制器
  4. *
  5. */
  6. namespace app\api\controller\v1;
  7. use app\api\controller\Api;
  8. use app\api\controller\YqlData;
  9. use app\api\service\PayNotifyService;
  10. use app\common\library\AirwallexPay;
  11. use app\common\model\Pay;
  12. use app\common\model\PayCpinfo;
  13. use app\common\model\Members;
  14. use app\common\logic\PayCallback;
  15. use app\common\logic\Pay as PayLogic;
  16. use app\common\library\WeixinPay;
  17. use app\service\PayService;
  18. use app\service\TiktokService;
  19. use http\Env\Request;
  20. use think\Config;
  21. use think\Db;
  22. use think\Env;
  23. use app\common\factory\Pay as NotifPay;
  24. use think\Validate;
  25. class PayNotify extends Api
  26. {
  27. protected $payErrMsg = ""; // 支付回调处理的错误信息
  28. protected $notifyData = ""; // 支付回调的原始数据
  29. /**
  30. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  31. */
  32. public function _initialize()
  33. {
  34. try {
  35. $this->notifyData = input();
  36. if (!$this->notifyData) {
  37. $this->notifyData = request()->getInput();
  38. }
  39. log_message('REQ.rawInput:'. json_encode($this->notifyData), 'log', LOG_PATH . 'PayNotify/');
  40. } catch (\Exception $e) {
  41. exit("fail: 处理异常!");
  42. }
  43. }
  44. /**
  45. * 支付宝服务器异步通知页面方法
  46. */
  47. public function alipay()
  48. {
  49. vendor('alipay.lib.AlipayNotify');
  50. $alipayNotify = new \AlipayNotify(Config::get('alipay'));
  51. $result = $alipayNotify->verifyNotify();
  52. $out_trade_no = input('out_trade_no'); //订单号
  53. //写入日志
  54. log_message("## alipay: ". $out_trade_no.' - '.($result?"success":"fail"), 'log', LOG_PATH . '../paylog/');
  55. if ($result) {
  56. // 处理支付成功后的逻辑业务
  57. if (input('post.trade_status') == 'TRADE_SUCCESS') {
  58. if (!empty($out_trade_no)) {
  59. //更新订单状态处理
  60. $this->updateOrder($out_trade_no, input('total_fee'));
  61. }
  62. echo 'success';
  63. exit; //请不要修改或删除
  64. }
  65. echo 'fail';
  66. exit; //验证失败
  67. }
  68. echo 'fail';
  69. exit;
  70. }
  71. /**
  72. * 支付宝Aop支付服务器异步通知页面方法
  73. */
  74. public function alipayAop()
  75. {
  76. //Alipay Aop Sdk支付回调
  77. vendor('alipayAop.AopSdk');
  78. $app_id = input('app_id');
  79. $out_trade_no = input('out_trade_no', ''); //订单号
  80. $configs = Config::get('ali_pay_config');
  81. $configs_list = array_keys($configs['configs']);
  82. if(!in_array($app_id, $configs_list)){
  83. ddMsg('warning', '', ['PayNotify.alipayAop.fail', '回调时 appId 配置不存在!', $app_id.'-'.$out_trade_no]);
  84. echo "fail";
  85. exit; //验证失败
  86. }
  87. $aop = new \AopClient();
  88. $aop->alipayrsaPublicKey = $configs['configs'][$app_id]['public_key'];
  89. $result = $aop->rsaCheckV1(input(), NULL, $configs['sign_type']);
  90. if ($result) {
  91. // 处理支付成功后的逻辑业务
  92. // 交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)、TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、TRADE_SUCCESS(交易支付成功)、TRADE_FINISHED(交易结束,不可退款)
  93. if (in_array(input('post.trade_status'), ['TRADE_SUCCESS', 'TRADE_CLOSED'])) {
  94. //写入日志
  95. // log_message("## alipayAop: ". $out_trade_no .' - '. $result, 'log', LOG_PATH . '../paylog/');
  96. if (!empty($out_trade_no)) {
  97. // total_amount=订单金额, refund_fee=退款金额
  98. //更新订单状态处理
  99. $this->updateOrder($out_trade_no, input('total_amount'), 'ali_pay');
  100. }
  101. echo 'success';
  102. exit; //请不要修改或删除
  103. }
  104. echo 'fail';
  105. exit; //验证失败
  106. }
  107. ddMsg('weelfar', '', ['PayNotify.alipayAop.fail', '回调失败!', $app_id.'-'.$out_trade_no]);
  108. echo 'fail';
  109. exit;
  110. }
  111. /**
  112. * 威富通-微信 支付完成回调处理
  113. *
  114. */
  115. public function swiftpay()
  116. {
  117. vendor('swiftpay.ClientResponseHandler', '.class.php');
  118. $resHandler = new \ClientResponseHandler(); //后台应答类
  119. $xml = file_get_contents('php://input');
  120. //写入日志
  121. log_message($xml, 'log', LOG_PATH . '../paylog/');
  122. $resHandler->setContent($xml);
  123. $resHandler->setKey(Config::get('swiftpay')['key']);
  124. //签名验证
  125. if ($resHandler->isTenpaySign()) {
  126. if ($resHandler->getParameter('status') == 0 && $resHandler->getParameter('result_code') == 0) {
  127. //支付成功时
  128. if ($resHandler->getParameter('pay_result') == 0) {
  129. $orderid = $resHandler->getParameter('out_trade_no');
  130. $total_fee = $resHandler->getParameter('total_fee') / 100; //金额,分为单位
  131. //订单编号不为空时
  132. if (!empty($orderid)) {
  133. //更新订单状态处理
  134. $this->updateOrder($orderid, $total_fee);
  135. }
  136. } else {
  137. //写入日志
  138. log_message('支付失败', 'error', LOG_PATH . '../paylog/');
  139. }
  140. echo 'success';
  141. exit();
  142. } else {
  143. echo 'failure1';
  144. exit();
  145. }
  146. } else {
  147. //写入日志
  148. log_message('威富通-微信 支付签名验证失败', 'error', LOG_PATH . '../paylog/');
  149. echo 'failure2';
  150. exit();
  151. }
  152. exit();
  153. }
  154. /**
  155. * 威富通中信银行-微信WAP支付回调处理
  156. *
  157. */
  158. public function swiftccbwxpay()
  159. {
  160. vendor('swiftpay.ClientResponseHandler', '.class.php');
  161. $resHandler = new \ClientResponseHandler(); //后台应答类
  162. $xml = file_get_contents('php://input');
  163. //写入日志
  164. log_message($xml, 'log', LOG_PATH . '../paylog/');
  165. $resHandler->setContent($xml);
  166. $resHandler->setRSAKey(Config::get('swiftccbwxpay')['public_key']);
  167. $resHandler->setParameter('sign_type', 'RSA_1_256');
  168. //签名验证
  169. if ($resHandler->isTenpaySign()) {
  170. if ($resHandler->getParameter('status') == 0 && $resHandler->getParameter('result_code') == 0) {
  171. //支付成功时
  172. if ($resHandler->getParameter('pay_result') == 0) {
  173. $orderid = $resHandler->getParameter('out_trade_no');
  174. $total_fee = $resHandler->getParameter('total_fee') / 100; //金额,分为单位
  175. //订单编号不为空时
  176. if (!empty($orderid)) {
  177. //更新订单状态处理
  178. $this->updateOrder($orderid, $total_fee);
  179. }
  180. } else {
  181. //写入日志
  182. log_message('支付失败', 'error', LOG_PATH . '../paylog/');
  183. }
  184. echo 'success';
  185. exit();
  186. } else {
  187. echo 'failure1';
  188. exit();
  189. }
  190. } else {
  191. //写入日志
  192. log_message('威富通-微信 支付签名验证失败', 'error', LOG_PATH . '../paylog/');
  193. echo 'failure2';
  194. exit();
  195. }
  196. exit();
  197. }
  198. /**
  199. * 第三方 现在支付完成回调处理
  200. *
  201. */
  202. public function zfbxjzfipaynow()
  203. {
  204. //返回的参数
  205. $res = file_get_contents('php://input');
  206. //写入日志
  207. log_message('现在支付回调参数:' . $res, 'log', LOG_PATH . '../paylog/');
  208. $Arr = array();
  209. $res = explode('&', $res);
  210. //写入日志
  211. log_message('现在支付explode处理后的回调参数:' . print_r($res, true), 'log', LOG_PATH . '../paylog/');
  212. foreach ($res as $v) {
  213. $value = explode('=', $v);
  214. $Arr[$value[0]] = urldecode($value[1]);
  215. }
  216. $signatrue = $this->getIpaynowSignTrue($Arr, Config::get('h5_alipay_config')['key']);
  217. if ($signatrue == $Arr['signature']) {
  218. $orderid = $Arr['mhtOrderNo'];
  219. $mhtOrderAmt = $Arr['mhtOrderAmt'] / 100; //商户订单交易金额,以分为单位
  220. //订单编号不为空时
  221. if (!empty($orderid)) {
  222. //更新订单状态处理
  223. $this->updateOrder($orderid, $mhtOrderAmt);
  224. }
  225. //异步通知验签通过,在此处写业务逻辑
  226. echo 'success=Y';
  227. } else {
  228. //写入日志
  229. log_message('现在支付签名验证失败', 'error', LOG_PATH . '../paylog/');
  230. //异步通知验签失败,在此处写业务逻辑
  231. echo 'success=N';
  232. }
  233. }
  234. /**
  235. * 现在支付完成回调处理
  236. *
  237. */
  238. public function ipaynow()
  239. {
  240. //返回的参数
  241. $res = file_get_contents('php://input');
  242. //写入日志
  243. log_message('现在支付回调参数:' . $res, 'log', LOG_PATH . '../paylog/');
  244. $Arr = array();
  245. $res = explode('&', $res);
  246. //写入日志
  247. log_message('现在支付explode处理后的回调参数:' . print_r($res, true), 'log', LOG_PATH . '../paylog/');
  248. foreach ($res as $v) {
  249. $value = explode('=', $v);
  250. $Arr[$value[0]] = urldecode($value[1]);
  251. }
  252. $signatrue = $this->getIpaynowSignTrue($Arr, Config::get('h5_alipay_config')['key']);
  253. if ($signatrue == $Arr['signature'] && $Arr['transStatus'] == 'A001') {
  254. $orderid = $Arr['mhtOrderNo'];
  255. $mhtOrderAmt = $Arr['mhtOrderAmt'] / 100; //商户订单交易金额,以分为单位
  256. //订单编号不为空时
  257. if (!empty($orderid)) {
  258. //更新订单状态处理
  259. $this->updateOrder($orderid, $mhtOrderAmt);
  260. }
  261. //异步通知验签通过,在此处写业务逻辑
  262. echo 'success=Y';
  263. } else {
  264. //写入日志
  265. log_message('现在支付签名验证失败', 'error', LOG_PATH . '../paylog/');
  266. //异步通知验签失败,在此处写业务逻辑
  267. echo 'success=N';
  268. }
  269. }
  270. /**
  271. * 对现在支付回调的请求报文做签名验证,
  272. * copy现在支付demo代码中controller.php的getSignTrue方法
  273. *
  274. * @param $Arr array 报文参数
  275. * @param $key string
  276. *
  277. * @return mix
  278. */
  279. private function getIpaynowSignTrue($Arr, $key)
  280. {
  281. if (!empty($Arr)) {
  282. ksort($Arr);
  283. $str = '';
  284. foreach ($Arr as $k => $v) {
  285. if ($v == '' || $k == 'signature') {
  286. continue;
  287. }
  288. $str .= $k . '=' . $v . '&';
  289. }
  290. if ($key == 'post') {
  291. return substr($str, 0, -1);
  292. } else {
  293. return strtolower(md5($str . md5($key)));
  294. }
  295. }
  296. return false;
  297. }
  298. /**
  299. * 微信官方h5支付
  300. */
  301. public function wxpayh5()
  302. {
  303. $request_data = file_get_contents('php://input');
  304. //写入日志
  305. log_message('微信h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  306. $wxPay = new WeixinPay;
  307. $data = $wxPay->xmlToArray($request_data);
  308. $data = array_filter($data);
  309. $source_sign = $data['sign']; // 接收到的签名
  310. unset($data['sign']); // 参数中的sign不参与签名
  311. //生成的签名
  312. $sign = $wxPay->MakeSign($data, Config::get('wxpay-h5')['key']);
  313. //验签失败
  314. if ($source_sign !== $sign) {
  315. $return['return_code'] = 'failure';
  316. $return['return_msg'] = 'NO';
  317. //写入日志
  318. log_message('微信官方h5支付签名验证失败:' . print_r($data, true), 'error', LOG_PATH . '../paylog/');
  319. } elseif ('SUCCESS' != $data['result_code']) {
  320. $return['return_code'] = 'failure';
  321. $return['return_msg'] = 'NO';
  322. //写入日志
  323. log_message('微信官方h5支付错误代码:' . $data['err_code'] . '; 错误信息: ' . $data['err_code_des'], 'error', LOG_PATH . '../paylog/');
  324. } else {
  325. $orderid = $data['out_trade_no'];
  326. $amount = $data['total_fee'] / 100; //商户订单交易金额,以分为单位
  327. //订单编号不为空时
  328. if (!empty($orderid)) {
  329. //更新订单状态处理
  330. $this->updateOrder($orderid, $amount);
  331. }
  332. $return['return_code'] = 'SUCCESS';
  333. $return['return_msg'] = 'OK';
  334. }
  335. echo dataToXml($return);
  336. exit;
  337. }
  338. /**
  339. * 米花微信h5支付
  340. */
  341. public function wxpayh5mihua()
  342. {
  343. $request_data = file_get_contents('php://input');
  344. //写入日志
  345. log_message('米花微信h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  346. vendor('mihuaSdk.Mihua', '.class.php');
  347. $mihua = new \Mihua();
  348. $data = $_GET['data'];
  349. $retjson = $mihua->notifyVerify($data);
  350. if ($retjson && $retjson['orderStatus'] == 'SUCCESS') {
  351. $orderid = $retjson['orderId'];
  352. $amount = floatval($retjson['amount']);
  353. //订单编号不为空时
  354. if (!empty($orderid)) {
  355. //更新订单状态处理
  356. $this->updateOrder($orderid, $amount);
  357. }
  358. echo "SUCCESS";
  359. die();
  360. } else {
  361. log_message('米花微信h5支付签名验证失败:' . print_r($data, true), 'error', LOG_PATH . '../paylog/');
  362. echo 'FAIL';
  363. exit();
  364. }
  365. }
  366. /**
  367. * 米花支付宝h5支付
  368. */
  369. public function zfbh5mihua()
  370. {
  371. $request_data = file_get_contents('php://input');
  372. //写入日志
  373. log_message('米花支付宝h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  374. vendor('mihuaSdk.Mihuazfb', '.class.php');
  375. $mihua = new \Mihuazfb();
  376. $data = $_GET['data'];
  377. $retjson = $mihua->notifyVerify($data);
  378. if ($retjson && $retjson['orderStatus'] == 'SUCCESS') {
  379. $orderid = $retjson['orderId'];
  380. $amount = floatval($retjson['amount']);
  381. //订单编号不为空时
  382. if (!empty($orderid)) {
  383. //更新订单状态处理
  384. $this->updateOrder($orderid, $amount);
  385. }
  386. echo "SUCCESS";
  387. die();
  388. } else {
  389. log_message('米花支付宝h5支付签名验证失败:' . print_r($data, true), 'error', LOG_PATH . '../paylog/');
  390. echo 'FAIL';
  391. exit();
  392. }
  393. }
  394. /**
  395. * 快接微信h5支付
  396. */
  397. public function wxpayh5kj()
  398. {
  399. $request_data = file_get_contents('php://input');
  400. //写入日志
  401. log_message('快接微信h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  402. vendor('kjpaySdk.Kjpay', '.class.php');
  403. $kjpay = new \Kjpay();
  404. $data = $_POST;
  405. $retjson = $kjpay->notifyVerify($data);
  406. if ($retjson && $retjson['status'] == 'Success') {
  407. $orderid = $retjson['merchant_order_no'];
  408. $amount = floatval($retjson['amount']);
  409. //订单编号不为空时
  410. if (!empty($orderid)) {
  411. //更新订单状态处理
  412. $this->updateOrder($orderid, $amount);
  413. }
  414. echo "success";
  415. die();
  416. } else {
  417. log_message('快接微信h5支付签名验证失败:' . print_r($data, true), 'error', LOG_PATH . '../paylog/');
  418. echo 'fail';
  419. exit();
  420. }
  421. }
  422. /**
  423. * 快接支付宝h5支付
  424. */
  425. public function zfbh5kj()
  426. {
  427. $request_data = file_get_contents('php://input');
  428. //写入日志
  429. log_message('快接支付宝h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  430. vendor('kjpaySdk.Kjzfb', '.class.php');
  431. $kjpay = new \Kjzfb();
  432. $data = $_POST;
  433. $retjson = $kjpay->notifyVerify($data);
  434. if ($retjson && $retjson['status'] == 'Success') {
  435. $orderid = $retjson['merchant_order_no'];
  436. $amount = floatval($retjson['amount']);
  437. //订单编号不为空时
  438. if (!empty($orderid)) {
  439. //更新订单状态处理
  440. $this->updateOrder($orderid, $amount);
  441. }
  442. echo "success";
  443. die();
  444. } else {
  445. log_message('快接支付宝h5支付签名验证失败:' . print_r($data, true), 'error', LOG_PATH . '../paylog/');
  446. echo 'fail';
  447. exit();
  448. }
  449. }
  450. /**
  451. * 商盟微信h5支付
  452. */
  453. public function wxpayh5sumpay()
  454. {
  455. $request_data = file_get_contents('php://input');
  456. //写入日志
  457. log_message('商盟微信h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  458. vendor('sumpaySdk.Sumpay', '.class.php');
  459. $sumpay = new \Sumpay();
  460. $retData = array();
  461. $data = $_REQUEST;
  462. $retjson = $sumpay->notifyVerify($data);
  463. if ($retjson && $retjson['status'] == '1') {
  464. $orderid = trim($retjson['orderNo']);
  465. $amount = floatval($retjson['orderAmount']);
  466. //订单编号不为空时
  467. if (!empty($orderid)) {
  468. //更新订单状态处理
  469. $this->updateOrder($orderid, $amount);
  470. }
  471. $retData['code'] = '10000';
  472. echo json_encode($retData);
  473. exit();
  474. } else {
  475. log_message('商盟微信h5支付签名验证失败:' . print_r($data, true), 'error', LOG_PATH . '../paylog/');
  476. $retData['code'] = '30000';
  477. echo json_encode($retData);
  478. exit();
  479. }
  480. }
  481. /**
  482. * 酷点h5支付
  483. */
  484. public function kdh5zhifu()
  485. {
  486. $request_data = file_get_contents('php://input');
  487. log_message('酷点h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  488. vendor('kdpaySdk.des');
  489. $sumpay = new \kdpay();
  490. $data = json_decode($request_data, true);
  491. $res_result = json_decode($data['result'], true);
  492. if ($res_result['status'] == '100') {
  493. $retjson = $sumpay->notifyVerify($data);
  494. if ($retjson == $data['sign']) {
  495. $orderid = trim($res_result['out_trade_no']);
  496. $amount = floatval($res_result['fee'] / 100);
  497. //订单编号不为空时
  498. if (!empty($orderid)) {
  499. //更新订单状态处理
  500. $this->updateOrder($orderid, $amount);
  501. }
  502. echo "success";
  503. die();
  504. } else {
  505. echo 'fail';
  506. exit();
  507. }
  508. } else {
  509. echo '支付失败';
  510. exit();
  511. }
  512. }
  513. /**
  514. * 汇付宝 微信H5支付回调
  515. */
  516. public function wxwapnotify()
  517. {
  518. //$param = request()->param();
  519. //写入日志
  520. //log_message('回调参数'.json_encode($param),'error',LOG_PATH . '../paylog/');
  521. $sign_key = Config::get('wxwappay-h5')['key'];
  522. $result = $_GET['result'];
  523. $pay_message = $_GET['pay_message'];
  524. $agent_id = $_GET['agent_id'];
  525. $jnet_bill_no = $_GET['jnet_bill_no'];
  526. $agent_bill_id = $_GET['agent_bill_id'];
  527. $pay_type = $_GET['pay_type'];
  528. $pay_amt = $_GET['pay_amt'];
  529. $remark = "";
  530. $return_sign = $_GET['sign'];
  531. $signStr = '';
  532. $signStr = $signStr . 'result=' . $result;
  533. $signStr = $signStr . '&agent_id=' . $agent_id;
  534. $signStr = $signStr . '&jnet_bill_no=' . $jnet_bill_no;
  535. $signStr = $signStr . '&agent_bill_id=' . $agent_bill_id;
  536. $signStr = $signStr . '&pay_type=' . $pay_type;
  537. $signStr = $signStr . '&pay_amt=' . $pay_amt;
  538. $signStr = $signStr . '&remark=' . $remark;
  539. $signStr = $signStr . '&key=' . $sign_key; //商户签名密钥
  540. $sign = '';
  541. $sign = md5($signStr);
  542. if ($sign == $return_sign) { //比较签名密钥结果是否一致,一致则保证了数据的一致性
  543. //订单编号不为空时
  544. if (!empty($agent_bill_id)) {
  545. //更新订单状态处理
  546. $this->updateOrder($agent_bill_id, $pay_amt);
  547. }
  548. echo "success";
  549. die();
  550. } else {
  551. echo 'fail';
  552. exit();
  553. }
  554. }
  555. /**
  556. * 汇付宝 微信H5支付回调
  557. */
  558. public function wxwapreturn()
  559. {
  560. echo 'fail';
  561. exit();
  562. }
  563. /**
  564. * TODO: 全民付 支付回调
  565. */
  566. public function qmf_pay()
  567. {
  568. /**
  569. * msgType=wx.orderQuery
  570. &payTime=2022-06-21 17:29:25
  571. &connectSys=OPENCHANNEL
  572. &sign=A188B6B03255E111F19A73D17CFC44ABEED713D88B5BE965D05028E0B3129CF6
  573. &merName=中保付测试商户(中保付测试商户)
  574. &mid=898201612345678
  575. &invoic eAmount=1
  576. &settleDate=2022-06-21
  577. &billFunds=现金支付0.01元。
  578. &buyerId=o8wNP0Rl-a0Xz0FPKsxgSHEv2jYs
  579. &mchntUuid=6d47dc12a4c847eaba2eb456d201d5cd
  580. &tid=88880001
  581. &instMid=QRPAYDEF AULT
  582. &receiptAmount=1
  583. &targetOrderId=4200001498202206214650782137
  584. &signType=SHA256
  585. &orderDesc=全攻坚补款
  586. &seqId=01120706254N
  587. &merOrderId=319420220 621172858801SF554320
  588. &targetSys=WXPay
  589. &totalAmount=1
  590. &createTime=2022-06-21 17:29:13
  591. &buyerPayAmount=1
  592. &notifyId=32ae8766-bbbe-4c40-a1bd-7c082ffe668b
  593. &HC=ogHg
  594. &subInst=100200
  595. &status=TRADE_SUCCESS
  596. */
  597. $request_data = file_get_contents('php://input');
  598. log_message('全民付 支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/');
  599. $data = json_decode($request_data, true);
  600. if ($data['status'] == 'TRADE_SUCCESS') {
  601. $sign = $this->notifyVerify($data, 'xxxx');
  602. if ($sign == $data['sign']) {
  603. $orderid = trim($data['merOrderId']);
  604. $amount = floatval($data['totalAmount'] * 100);
  605. //订单编号不为空时
  606. if (!empty($orderid)) {
  607. //更新订单状态处理
  608. $this->updateOrder($orderid, $amount);
  609. }
  610. echo "SUCCESS";
  611. exit();
  612. } else {
  613. echo 'FAILED';
  614. exit();
  615. }
  616. } else {
  617. echo 'FAILED';
  618. exit();
  619. }
  620. }
  621. public function notifyVerify($data, $appkey){
  622. unset($data['sign']);
  623. $Parameters = [];
  624. foreach ($data as $k => $v) {
  625. if($v && $v != ""){
  626. $Parameters[$k] = $v;
  627. }
  628. }
  629. //签名步骤一:按字典序排序参数
  630. ksort($Parameters);
  631. $buff = "";
  632. foreach ($Parameters as $k => $v) {
  633. $buff .= $k . "=" . $v . "&";
  634. }
  635. $String = $buff . $appkey;
  636. //签名步骤三:MD5加密
  637. // $sign = md5($String);
  638. $sign = hash('sha256', $String);
  639. return $sign;
  640. }
  641. // 易宝支付 - 支付回调
  642. public function ybzf_pay(){
  643. // 文档: https://www.eolink.com/share/inside/f8LYBC/api/2161864/detail/48968582
  644. $postData = input();
  645. if($postData['returncode'] != '0000'){
  646. ddMsg('warning', '', ['PayNotify.ybzf_pay.fail', '失败订单回调!', $postData['paytype'].'-'.$postData['orderno']]);
  647. echo "fail";
  648. exit();
  649. }
  650. $private_key = Config::get('ybzf_pay')['private_key'];
  651. // 签名要求: MD5(paytime=xxx|orderno=xxxxx|payno=xxxx|paytype=xxx|productprice=xxxx|商户密钥)
  652. $signData = [
  653. 'paytime' => $postData['paytime'], // 支付时间 例:202209181022
  654. 'orderno' => $postData['orderno'], // 订单号
  655. 'payno' => $postData['payno'], // 系统号
  656. 'paytype' => $postData['paytype'], // 支付类型: 1=支付宝、2=微信、3=联快捷、4=程序、5=务窗、6=APP、7=钱包
  657. 'productprice' => $postData['productprice'], // 商品价格(单位:分)
  658. ];
  659. $signHandle = '';
  660. foreach ($signData as $k=>$v) {
  661. if($signHandle){
  662. $signHandle .= '|';
  663. }
  664. $signHandle .= $k.'='.$v;
  665. }
  666. $sign = md5($signHandle.'|'.$private_key);
  667. $result = $postData['sign'] == $sign;
  668. //写入日志
  669. log_message("## ybzf_pay: ". $signData['orderno'].' - sign: '.$postData['sign'] .' - '. $sign.' - res:'.($result?"success":"fail"), 'log', LOG_PATH . '../paylog/');
  670. if($result){
  671. if (!empty($signData['orderno'])) {
  672. // 更新订单状态处理
  673. $this->updateOrder($signData['orderno'], formatFenToYuan($postData['productprice']));
  674. }
  675. echo "success";
  676. exit();
  677. }
  678. ddMsg('weelfar', '', ['PayNotify.ybzf_pay.fail', '回调失败!', $postData['paytype'] . '-' . $postData['orderno']]);
  679. echo "fail";
  680. exit();
  681. }
  682. // 联动优势-微信小程序 - 支付回调
  683. public function ldzf_wx_pay()
  684. {
  685. $input = input();
  686. if (!$input) {
  687. $input = request()->getInput();
  688. }
  689. $result = NotifPay::makeNotify('ldys_pay', $input);
  690. if ($result['error'] == false) {
  691. if ($this->updateOrder($input['order_id'], formatFenToYuan($input['amount'])) == true) {
  692. echo NotifPay::makeReturnNotify("ldys_pay", $result['result']);
  693. exit();
  694. }
  695. }
  696. echo NotifPay::makeReturnNotify('ldys_pay', 'fail');
  697. exit();
  698. }
  699. // 趣智连支付 - 支付回调
  700. public function qzl_pay()
  701. {
  702. // 【参数内容重置获取】获取原始请求体,保留 + 号(PHP 的 $_POST/parse_str 会把 + 转成空格)
  703. $this->notifyData = file_get_contents('php://input');
  704. $this->notifyData = parseParamsKeepPlus($this->notifyData);
  705. if (!$this->notifyData) {
  706. $this->notifyData = input();
  707. }
  708. $input = $this->notifyData;
  709. // dump($this->notifyData);
  710. $notifyResult = NotifPay::makeNotify('qzl_pay', $input);
  711. $result = $notifyResult['result'];
  712. if ($notifyResult['result'] == "success") {
  713. if ($this->updateOrder($input['mchOrderNo'], formatFenToYuan($input['amount']), 'qzl_pay') == false) {
  714. $result = 'fail:订单号不存在或金额有误!';
  715. if($this->payErrMsg){
  716. $result = $this->payErrMsg;
  717. }
  718. }
  719. }
  720. echo $result;
  721. if($result != "success"){
  722. trace('PayNotify.qzl_pay.err.result: ' . $result, 'log');
  723. }
  724. exit();
  725. }
  726. // 优亿支付 - 支付回调
  727. public function yyyb_pay()
  728. {
  729. $input = input();
  730. if (!$input) {
  731. $input = request()->getInput();
  732. }
  733. $result = NotifPay::makeNotify('yyyb_pay', $input);
  734. if ($result['result'] == "success") {
  735. if ($this->updateOrder($input['mchOrderNo'], formatFenToYuan($input['amount'])) == false) {
  736. $result['result'] = NotifPay::makeReturnNotify('qzl_pay', 'fail');
  737. }
  738. }
  739. echo $result['result'];
  740. exit();
  741. }
  742. // 喜钛游
  743. public function xty_pay()
  744. {
  745. $input = $this->notifyData;
  746. try {
  747. if(is_json($input)){
  748. $input = json_decode($input, true);
  749. }
  750. $notifyResult = NotifPay::makeNotify('xty_pay', $input);
  751. $result = $notifyResult['result'];
  752. if ($notifyResult['result'] == "success") {
  753. $signData = json_decode($input["req_data"], true);
  754. if ($this->updateOrder($signData['out_trade_no'], formatFenToYuan($signData['total_amount']), 'xty_pay') == false) {
  755. $result = 'fail:订单号不存在或金额有误!';
  756. }
  757. if($this->payErrMsg){
  758. $result = 'fail:'.$this->payErrMsg;
  759. }
  760. }
  761. } catch (\Exception $e) {
  762. $result = "fail:支付回调异常:" . $e->getMessage();
  763. }
  764. echo $result;
  765. if($result != "success"){
  766. trace('PayNotify.yyyb_pay.err.result: ' . $result, 'log');
  767. }
  768. exit();
  769. }
  770. public function pay_refund(){
  771. die('xxx');
  772. $orderid = makeOrderid('TK_');
  773. // $input = input();
  774. // $payInfo = Db::table('cy_pay')->field('id,orderid,status,amount,real_amount,userid,gameid,channel_id,ip,coupon_member_id,coupon_amount,real_coin,coupon_member_id')->where(['orderid' => $input['orderid']])->find();
  775. // $refundData = [
  776. // "out_trade_no" => $payInfo['orderid'], // 商户订单号
  777. // // "order_no" => $order_no, // 交易流水号
  778. // "out_refund_no" => $orderid, // 商户退款单号
  779. // "refund_amount" => formatYuanToFen($payInfo['real_amount']), // 退款金额(分)
  780. // "refund_reason" => "订单已取消,系统退款处理", // 退款原因
  781. // ];
  782. $refundData = [
  783. "out_trade_no" => "WL17739740192510156790", // 商户订单号
  784. "out_refund_no" => $orderid, // 交易流水号
  785. // "refund_amount" => 0.01, // 退款金额(元)
  786. "refund_amount" => formatYuanToFen(0.01), // 退款金额(分)
  787. "refund_reason" => "订单已取消,系统退款处理", // 退款原因
  788. ];
  789. //订单使用了代金卷或平台币,则进行退款处理
  790. // $refundRsult = \app\common\factory\Pay::makeRefund('ali_pay', $refundData);
  791. $refundRsult = \app\common\factory\Pay::makeRefund('xty_pay', $refundData);
  792. dump($refundRsult);
  793. }
  794. /**
  795. * 更新订单信息
  796. *
  797. * @param string $orderid :订单编号
  798. * @param string $real_amount :第三方支付的金额(现金部分)(单位:元:6.48)
  799. * @param string $paytype :支付类型
  800. *
  801. * @return boolean
  802. */
  803. private function updateOrder($orderid, $real_amount = '', $paytype = '')
  804. {
  805. $payModel = new Pay;
  806. $payCpinfoModel = new PayCpinfo;
  807. $membersModel = new Members;
  808. $result = false;
  809. // ## 订单信息
  810. $payInfo = $payModel->field('id,status,amount,real_amount,userid,gameid,channel_id,ip,coupon_member_id,coupon_amount,real_coin,coupon_member_id')->where(['orderid' => $orderid])->find();
  811. // dump($payInfo);
  812. if(!$payInfo){
  813. return "当前订单不存在!";
  814. }
  815. if ($payInfo['status'] == 1 && $payInfo['real_amount'] == $real_amount) {
  816. return true;
  817. }
  818. // TODO: 缺少订单如果成功后,又取消的订单回调时,处理订单状态由已成功改为已取消;(需要查第三方订单状态确实)
  819. /**
  820. * ## 订单已取消处理
  821. * - 第三方返回支付成功,检测订单状态为已取消时,检测此订单是否包含平台币/代金券,包含任意其中一个则自动退款,不包含则订单成功;
  822. */
  823. if(in_array($payInfo['status'], [2, 3]) && $paytype){
  824. // 如果交易包含 平台币或代金券,则进行退款处理
  825. if($payInfo['real_amount'] > 0 || $payInfo['real_coin'] > 0 || $payInfo['coupon_amount'] > 0){
  826. trace("0. 退款中 - Loading: orderid={$orderid}, refund_amount={$payInfo['real_amount']}", 'log');
  827. // $refundOrderId = makeOrderid('REF');
  828. $refundData = [
  829. "out_trade_no" => $orderid, // 商户订单号(祈盟)
  830. // "order_no" => $order_no, // 交易流水号(商户平台)
  831. "out_refund_no" => $orderid.'_T', // 商户退款单号
  832. "refund_amount" => $payInfo['real_amount'], // 退款金额(元)
  833. "refund_reason" => "订单已取消,系统自动退款处理", // 退款原因
  834. ];
  835. $refundRsult = \app\common\factory\Pay::makeRefund($paytype, $refundData);
  836. // 退款 - 已处理过
  837. if($refundRsult['code'] == 210){
  838. return true;
  839. }
  840. // 退款 - 处理成功
  841. if($refundRsult['code'] != 200){
  842. $this->payErrMsg = $refundRsult['msg'];
  843. trace("-1. 退款失败 - FAIL: orderid={$orderid}, msg=". $refundRsult['msg'], 'log');
  844. return false;
  845. }
  846. trace("1. 退款成功 - SUCCESS: orderid={$orderid}, msg=". $refundRsult['msg'], 'log');
  847. $payModel->where(['id' => $payInfo['id']])->update(['status' => 2, 'beizhu' => '订单已取消,系统自动退款处理']); // 更新订单状态为 超时取消
  848. return true;
  849. }
  850. }
  851. // ## 支付成功,通知CP
  852. if ($payInfo['status'] == 1) {
  853. (new PayCallback())->callBackToCp($orderid);
  854. // 代金卷使用成功通知
  855. if (!empty($payInfo['coupon_member_id'])) {
  856. (new \app\api\controller\YqlData())->notifyCoupon($payInfo['coupon_member_id']);
  857. }
  858. return true;
  859. }
  860. if ($real_amount != '' && strval($payInfo['real_amount']) != $real_amount) {
  861. $result = false;
  862. //写入日志
  863. log_message('订单编号:' . $orderid . '支付金额不一致,订单状态更新失败', 'error', RUNTIME_PATH . 'paylog/');
  864. }
  865. // 待支付状态时
  866. elseif ($payInfo['status'] == 0 || $payInfo['status'] == 2) {
  867. // 启动事务
  868. Db::startTrans();
  869. try {
  870. cache('PayNotify:updateOrder:' . $orderid, $payInfo, 300);
  871. $payModel->where(['id' => $payInfo['id']])->update(['status' => 1, 'pay_time' => NOW_TIMESTAMP]);
  872. //cy_paycpinfo表记录状态更新
  873. $payCpinfoModel->where(['orderid' => $orderid])->update(['payflag' => 1]);
  874. //增加用户积分
  875. $this->memberjifen($payInfo['userid'], $payInfo['gameid'], $payInfo['real_amount']);
  876. //代金券处理
  877. if($payInfo['coupon_member_id']>0 && $payInfo['coupon_amount']>0){
  878. model('common/CouponMember')->updateCouponIsUseById($payInfo['coupon_member_id'],3);
  879. }
  880. $result = true;
  881. // 提交事务
  882. Db::commit();
  883. // log_message('TiktokService:push:'.$orderid, 'info', LOG_PATH . '../tiktok/');
  884. //2022-10-13 抖音推送
  885. // $extend = [
  886. // 'Oaid' => '',
  887. // 'Idfa' => '',
  888. // 'Androidid' => '',
  889. // 'Imei' => '',
  890. // 'PayAmount' => $payInfo['amount'],
  891. // 'Ip' => $payInfo['ip']
  892. // ];
  893. // $tiktokService = new TiktokService();
  894. // $tiktokService->push('tiktok.active_pay', $payInfo['userid'], $payInfo['gameid'], $payInfo['channel_id'], $extend);
  895. } catch (\Exception $e) {
  896. // 回滚事务
  897. Db::rollback();
  898. $result = false;
  899. //写入日志
  900. log_message('订单编号:' . $orderid . '订单状态更新失败' . $e->getMessage(), 'error', RUNTIME_PATH . 'paylog/');
  901. }
  902. }
  903. //订单状态更新成功
  904. if ($result) {
  905. //更新member表的total_pay_amount
  906. $membersModel->where(['id' => $payInfo['userid']])->update(['total_pay_amount' => Db::raw('total_pay_amount+' . $payInfo['amount'])]);
  907. // 通知CP,支付成功
  908. (new PayCallback())->callBackToCp($orderid);
  909. //预警邮件
  910. (new PayLogic())->payWarning($payInfo['userid'], $payInfo['channel_id'], $payInfo['gameid'], $payInfo['amount']);
  911. // 代金卷使用成功通知
  912. if (!empty($payInfo['coupon_member_id'])) {
  913. (new YqlData())->notifyCoupon($payInfo['coupon_member_id']);
  914. }
  915. }
  916. return $result;
  917. }
  918. /**
  919. * 用户玩家积分
  920. */
  921. private function memberjifen($userid, $gameid, $amount)
  922. {
  923. $jifen_ratio = Db::name("cy_game")->where(['id' => $gameid])->value('jifen_ratio');
  924. if (!empty($jifen_ratio)) {
  925. $jifen = $amount * $jifen_ratio;
  926. } else {
  927. $jifen_ratio = 1;
  928. $jifen = $amount * $jifen_ratio;
  929. }
  930. $jifen_info['game_id'] = $gameid;
  931. $jifen_info['user_id'] = $userid;
  932. $jifen_info['amount'] = $amount;
  933. $jifen_info['type'] = 1;
  934. $jifen_info['jifen_ratio'] = $jifen_ratio;
  935. $jifen_info['jifen'] = $jifen;
  936. $jifen_info['create_time'] = time();
  937. Db::name("cy_member_jifen_record")->insert($jifen_info);
  938. Db::name("cy_members")->where(['id' => $userid])->update(['jifen' => Db::raw('jifen+' . $jifen)]);
  939. }
  940. public function airwallex()
  941. {
  942. $postData = request()->getInput();
  943. $header = [
  944. 'timestamp' => request()->header('x-timestamp') ?: time(),
  945. 'signature' => request()->header('x-signature') ?: '',
  946. ];
  947. log_message('header:' . json_encode(request()->header()) . ' data:' . $postData, 'log', LOG_PATH . 'PayNotify/airwallex/');
  948. $airwallexPay = new AirwallexPay();
  949. if ($airwallexPay->notify($postData, $header)) {
  950. $data = json_decode($postData, true);
  951. if (substr($data['data']['object']['merchant_order_id'], 0, 4) == 'COIN') {
  952. $orderid = $data['data']['object']['merchant_order_id'];
  953. $amount = floatval($data['data']['object']['amount']);
  954. $callback_order = $data['sourceId'];
  955. $currency = $data['data']['object']['currency'];
  956. //订单编号不为空时
  957. if (!empty($orderid)) {
  958. //更新订单状态处理
  959. (new PayNotifyService())->updateOrderCoin($orderid, $amount, $callback_order, $currency);
  960. }
  961. } else {
  962. $orderid = $data['data']['object']['merchant_order_id'];
  963. $amount = floatval($data['data']['object']['amount']);
  964. //订单编号不为空时
  965. if (!empty($orderid)) {
  966. //更新订单状态处理
  967. $this->updateOrder($orderid, $amount);
  968. }
  969. }
  970. echo 'ok';
  971. exit();
  972. } else {
  973. throw new \Exception('signature invalid');
  974. }
  975. }
  976. // 电魂支付回调
  977. public function dianhun(){
  978. // 获取请求参数 - 根据注释中的参数列表
  979. $input = \think\Request::instance()->only([
  980. 'qm_username', // 祈盟用户名
  981. 'qm_game_id', // 祈盟game_id
  982. 'order_id', // 游戏方订单号
  983. 'amount', // 金额(单位/元)
  984. 'product_name', // 商品名
  985. 'product_desc', // 商品介绍
  986. 'pay_type', // 支付方式(dh_zfb=支付宝/dh_wx=微信)
  987. 'create_time', // 下单时间
  988. 'pay_time', // 支付时间
  989. 'sign' // sign
  990. ], 'post');
  991. // 参数验证规则
  992. $validate = new Validate([
  993. 'qm_username' => 'require',
  994. 'qm_game_id' => 'require',
  995. 'order_id' => 'require',
  996. 'amount' => 'require',
  997. 'product_name' => 'require',
  998. 'pay_type' => 'require',
  999. 'create_time' => 'require',
  1000. 'pay_time' => 'require',
  1001. 'sign' => 'require',
  1002. ]);
  1003. // 验证参数
  1004. if (!$validate->check($input)) {
  1005. return '{"code": -110, "msg": "请求参数有误:'.$validate->getError().'"}';
  1006. }
  1007. try {
  1008. // 签名
  1009. $app_key = model('App')->where(['gameid' => $input['qm_game_id']])->value('appkey');
  1010. if(!$app_key){
  1011. return '{"code": -110, "msg": "当前游戏数据异常!"}';
  1012. }
  1013. ksort($input);
  1014. $str = '';
  1015. foreach($input as $k => $v){
  1016. if($k == 'sign'){
  1017. continue; // 跳过签名字段
  1018. }
  1019. if($str){
  1020. $str .= '&' . $k . '=' . $v;
  1021. }else{
  1022. $str .= $k . '=' . $v;
  1023. }
  1024. }
  1025. $sign = md5($str.$app_key);
  1026. if($sign != $input['sign']){
  1027. return '{"code": -110, "msg": "签名异常!"}';
  1028. }
  1029. $userInfo = Db::table('nw_subaccount')->alias('ns')
  1030. ->join('cy_members cm', 'ns.member_id = cm.id', 'left')
  1031. ->join('nw_member_game_server nmgs', 'ns.member_id = nmgs.member_id AND nmgs.game_id=ns.game_id AND nmgs.channel_id=ns.channel_id', 'left')
  1032. ->field("ns.member_id,ns.game_id,ns.channel_id,cm.username, nmgs.ip,nmgs.imeil,nmgs.roleid,nmgs.rolename,nmgs.rolelevel,nmgs.serverid,nmgs.servername")
  1033. ->where(['ns.sub_username' => $input['qm_username'], 'ns.game_id' => $input['qm_game_id']])
  1034. ->find();
  1035. if(!$userInfo){
  1036. return '{"code": -110, "msg": "当前账户数据异常!"}';
  1037. }
  1038. // 判断订单是否存在
  1039. if(Db::table('cy_pay')->where(['attach' => $input['order_id'], 'gameid' => $input['qm_game_id']])->count() > 0){
  1040. return '{"code": 200, "msg": "success."}';
  1041. }
  1042. $orderData = [
  1043. 'orderid' => makeOrderid(),
  1044. 'userid' => $userInfo['member_id'],
  1045. 'username' => $userInfo['username'],
  1046. 'channel_id' => $userInfo['channel_id'],
  1047. 'gameid' => $input['qm_game_id'],
  1048. 'status' => 1,
  1049. 'paytype' => $input['pay_type'],
  1050. 'amount' => $input['amount'], // 订单金额
  1051. 'real_amount' => $input['amount'], // 支付金额
  1052. // 角色信息
  1053. 'roleid' => $userInfo['roleid'],
  1054. 'rolename' => $userInfo['rolename'],
  1055. 'rolelevel' => $userInfo['rolelevel'],
  1056. 'productname' => $input['product_name'],
  1057. 'productdesc' => $input['product_desc'],
  1058. 'serverid' => $userInfo['serverid'],
  1059. 'servername' => $userInfo['servername'],
  1060. 'ip' => $userInfo['ip'],
  1061. 'imeil' => $userInfo['imeil'],
  1062. // 'create_time' => $input['create_time'],
  1063. // 'pay_time' => $input['pay_time'],
  1064. // 修改电魂订单的下单时间和支付时间逻辑(为了祈盟平台抓取数据方便,这里做修改);
  1065. 'create_time' => $input['pay_time'],
  1066. 'pay_time' => time(),
  1067. 'beizhu' => '电魂订单', // 备注
  1068. 'attach' => $input['order_id'], // CP扩展参数
  1069. 'discount' => 1, // 折扣比例
  1070. 'pay_amount' => $input['amount'], // 支付金额
  1071. ];
  1072. $result = Db::table('cy_pay')->insert($orderData);
  1073. if(!$result){
  1074. return '{"code": -130, "msg": "订单记录失败"}';
  1075. }
  1076. $cpInfo = [
  1077. 'orderid' => $orderData['orderid'],
  1078. 'appid' => 0,
  1079. 'status' => 1,
  1080. 'payflag' => 1,
  1081. 'create_time' => $input['create_time'],
  1082. 'update_time' => $input['pay_time'],
  1083. ];
  1084. $result = Db::table('cy_paycpinfo')->insert($cpInfo);
  1085. if(!$result){
  1086. return '{"code": -131, "msg": "订单详情记录失败"}';
  1087. }
  1088. return '{"code": 200, "msg": "success"}';
  1089. } catch (\Exception $e) {
  1090. $result = '{"code": -150, "msg": "请求参数异常:'.$e->getMessage().'"}';
  1091. log_message('订单存储失败:'. json_encode(input()).' - result: '.$result, 'log', LOG_PATH . 'PayNotifyDianHun/');
  1092. curlDD("电魂订单异常: input=" . json_encode(input()).' - error='. $result, Env::get('dingtalk.notic_url'));
  1093. return $result;
  1094. }
  1095. return '{"code": -120, "msg": "订单记录失败"}';
  1096. }
  1097. }