NoticeController.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. <?php
  2. namespace hd\controllers;
  3. use biz\common\classes\GhsNotifyClass;
  4. use biz\renew\classes\RenewClass;
  5. use biz\shop\classes\ShopClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\custom\classes\CustomRechargeClass;
  8. use bizGhs\express\classes\GhsDeliveryOrderClass;
  9. use bizGhs\order\classes\RefundOrderClass;
  10. use bizHd\cg\classes\CgRefundClass;
  11. use bizHd\ghs\classes\GhsClass;
  12. use bizHd\notice\classes\NoticeClass;
  13. use bizHd\purchase\classes\PurchaseClass;
  14. use bizHd\purchase\classes\PurchaseClearClass;
  15. use bizHd\wx\classes\WxOpenClass;
  16. use common\components\dict;
  17. use common\components\noticeUtil;
  18. use common\components\payUtil;
  19. use Yii;
  20. use common\components\util;
  21. use biz\wx\classes\WxMessageClass;
  22. use bizGhs\order\classes\OrderClass;
  23. use bizGhs\order\classes\ShMethodClass;
  24. use biz\shop\classes\ShopExtClass;
  25. use common\components\lakala\Lakala;
  26. use common\components\push;
  27. class NoticeController extends PublicController
  28. {
  29. public $categoryList;
  30. //收银台的回调通知 ssh 20231229
  31. public function actionCashPayCallback()
  32. {
  33. header("Content-type: text/html; charset=utf-8");
  34. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  35. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  36. if (empty($postStr)) {
  37. util::end();
  38. }
  39. $headers = Yii::$app->getRequest()->getHeaders();
  40. $Authorization = $headers->get('Authorization');
  41. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  42. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  43. $params = [
  44. 'appid' => 'OP00002119',
  45. 'serial_no' => '018b08cfddbd',
  46. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  47. 'lklCertificatePath' => $lklCertificatePath,
  48. ];
  49. $laResource = new Lakala($params);
  50. $return = $laResource->signatureVerification($Authorization, $postStr);
  51. $postData = json_decode($postStr, true);
  52. $orderSn = $postData['out_order_no'] ?? '';
  53. $merchant_no = $postData['merchant_no'] ?? '';
  54. $orderTradeInfo = $postData['order_trade_info'] ?? [];
  55. $payMode = $orderTradeInfo['pay_mode'] ?? null;
  56. if (empty($payMode)) {
  57. noticeUtil::push('收银台支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  58. util::end();
  59. }
  60. $trade_amount = $orderTradeInfo['trade_amount'] ?? 0;
  61. $totalFee = $trade_amount / 100;
  62. if ($totalFee <= 0) {
  63. noticeUtil::push('收银台支付回调验证失败了,金额错误,请注意,orderSn:' . $orderSn, '15280215347');
  64. util::end();
  65. }
  66. $transactionId = $orderTradeInfo['trade_no'] ?? 0;
  67. if ($return == false) {
  68. noticeUtil::push('收银台支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
  69. util::end();
  70. }
  71. $orderStatus = $postData['order_status'];
  72. $tradeType = $orderTradeInfo['trade_type'] ?? '';
  73. if ($tradeType != 'PAY') {
  74. noticeUtil::push('收银台支付回调验证失败了,不是消费的回调,orderSn:' . $orderSn, '15280215347');
  75. util::end();
  76. }
  77. //接收流水类型、代金劵
  78. $remarkString = $orderTradeInfo['trade_remark'] ?? '';
  79. $remarkData = json_decode($remarkString, true);
  80. //流水类型
  81. $capitalType = $remarkData['capitalType'] ?? null;
  82. if (!isset($capitalType)) {
  83. noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
  84. util::end();
  85. }
  86. $connection = Yii::$app->db;
  87. $transaction = $connection->beginTransaction();
  88. try {
  89. if ($orderStatus == 2) {
  90. $payWayType = null;
  91. if ($payMode == 'ALIPAY') {
  92. $payWayType = dict::getDict('payWay', 'alipay');
  93. }
  94. if ($payMode == 'WECHAT') {
  95. $payWayType = dict::getDict('payWay', 'wxPay');
  96. }
  97. if (isset($payWayType) == false) {
  98. noticeUtil::push('收银台支付回调验证失败了,没有找到支付方式,orderSn:' . $orderSn, '15280215347');
  99. util::end();
  100. }
  101. $attach = 'merchant_no=' . $merchant_no;
  102. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  103. $transaction->commit();
  104. }
  105. //请不要修改
  106. echo "SUCCESS";
  107. //解决重复通知
  108. $cacheKey = 'pay_success_notice_' . $orderSn;
  109. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  110. if (!empty($has)) {
  111. Yii::$app->end();
  112. }
  113. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  114. //客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
  115. if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
  116. $customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
  117. $customId = $customRecharge->customId ?? 0;
  118. $ghsId = $customRecharge->ghsId ?? 0;
  119. $ghs = GhsClass::getLockById($ghsId);
  120. $ghsShopId = $ghs->shopId ?? 0;
  121. $custom = CustomClass::getLockById($customId);
  122. $shop = ShopClass::getById($ghsShopId, true);
  123. // 销账已在 CustomRechargeClass::thirdPay 内按本次来款 FIFO 完成,勿再 useBalanceClear
  124. //充值销账通知
  125. WxMessageClass::customRechargeClearInform($shop, $customRecharge);
  126. }
  127. //零售线上结账通知
  128. if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
  129. $clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
  130. $customId = $clearInfo->customId ?? 0;
  131. $ghsShopId = $clearInfo->ghsShopId ?? 0;
  132. $ghsShop = ShopClass::getById($ghsShopId, true);
  133. $custom = CustomClass::getById($customId, true);
  134. if (!empty($custom) && !empty($ghsShop)) {
  135. WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  136. }
  137. }
  138. //零售采购通知
  139. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  140. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  141. $saleId = $cg->saleId ?? 0;
  142. $order = OrderClass::getById($saleId, true);
  143. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  144. GhsDeliveryOrderClass::payAfter($order);
  145. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  146. if (!empty($cg) && !empty($order)) {
  147. if (isset($cg->book) && $cg->book == 0) {
  148. $ghsShopId = $order->shopId ?? 0;
  149. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  150. if ($ext->orderFlow == 0) {
  151. PurchaseClass::confirmTake($cg);
  152. }
  153. }
  154. }
  155. //更新最后下单时间
  156. $customId = $order->customId ?? 0;
  157. $custom = CustomClass::getById($customId, true);
  158. $date = date("Y-m-d H:i:s");
  159. if (!empty($custom)) {
  160. $custom->recentExpend = $date;
  161. $custom->save();
  162. }
  163. $ghsId = $order->ghsId ?? 0;
  164. $ghs = GhsClass::getById($ghsId, true);
  165. if (!empty($ghs)) {
  166. $ghs->recentExpend = $date;
  167. $ghs->save();
  168. }
  169. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  170. if ($cg->transType != 5 && $cg->transType != 4) {
  171. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  172. $customId = $cg->customId ?? 0;
  173. $current = date("Y_m_d");
  174. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  175. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  176. }
  177. } else {
  178. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  179. $customId = $cg->customId ?? 0;
  180. if (isset($cg->sendType)) {
  181. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  182. $customId,
  183. $cg->sendType,
  184. $cg->sendCost ?? 0,
  185. $cg->packCost ?? 0
  186. );
  187. }
  188. }
  189. if (!empty($cg) && $cg->payStatus == 1) {
  190. //微信通知
  191. if (!empty($order)) {
  192. //订单生成时唤起在线打印
  193. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  194. //有几个地方要同步去修改
  195. if (getenv('YII_ENV') == 'production') {
  196. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  197. $mallOrderNoPrint = [10536, 44282, 26374];
  198. } else {
  199. $mallOrderNoPrint = [];
  200. }
  201. if (in_array($order->mainId, $mallOrderNoPrint)) {
  202. } else {
  203. OrderClass::onlinePrint($order);
  204. $order->printNum += 1;
  205. $order->save();
  206. if (getenv('YII_ENV') == 'production') {
  207. //福州我要花、花路鲜花批发、小齐鲜花、花镜打二次小票,有多处要修改搜索关键词tow_print
  208. $needTwoPrint = [7538, 36707, 76796, 94589];
  209. } else {
  210. $needTwoPrint = [644];
  211. }
  212. if (in_array($order->mainId, $needTwoPrint)) {
  213. if ($order->mainId == 7538) {
  214. OrderClass::onlinePrint($order, 0);
  215. } else {
  216. OrderClass::onlinePrint($order);
  217. }
  218. $order->printNum += 1;
  219. $order->save();
  220. }
  221. }
  222. }
  223. $cgShopId = $cg->shopId ?? 0;
  224. $cgShop = ShopClass::getById($cgShopId, true);
  225. if (!empty($cgShop)) {
  226. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  227. }
  228. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  229. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  230. ShopExtClass::ghsGatheringReport($order);
  231. }
  232. $shopId = $order->shopId ?? 0;
  233. $shop = ShopClass::getById($shopId, true);
  234. if (!empty($shop)) {
  235. GhsNotifyClass::newOrderNotify($saleId);
  236. }
  237. }
  238. }
  239. }
  240. exit();
  241. } catch (\Exception $e) {
  242. $transaction->rollBack();
  243. Yii::error("失败原因:" . $e->getMessage());
  244. }
  245. }
  246. //拉卡拉回调通知 ssh 20231009
  247. public function actionPayCallback()
  248. {
  249. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  250. if (empty($postStr)) {
  251. util::end();
  252. }
  253. $headers = Yii::$app->getRequest()->getHeaders();
  254. $Authorization = $headers->get('Authorization');
  255. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  256. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  257. $params = [
  258. 'appid' => 'OP00002119',
  259. 'serial_no' => '018b08cfddbd',
  260. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  261. 'lklCertificatePath' => $lklCertificatePath,
  262. ];
  263. $laResource = new Lakala($params);
  264. $return = $laResource->signatureVerification($Authorization, $postStr);
  265. $postData = json_decode($postStr, true);
  266. $orderSn = $postData['out_trade_no'] ?? '';
  267. $total_amount = $postData['total_amount'] ?? 0;
  268. $account_type = $postData['account_type'] ?? '';
  269. $merchant_no = $postData['merchant_no'] ?? '';
  270. if (empty($account_type)) {
  271. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  272. util::end();
  273. }
  274. $totalFee = $total_amount / 100;
  275. $transactionId = $postData['trade_no'] ?? 0;
  276. if ($return == false) {
  277. noticeUtil::push('支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
  278. util::end();
  279. }
  280. //接收流水类型、代金劵
  281. $remarkString = $postData['remark'] ?? '';
  282. $remarkData = json_decode($remarkString, true);
  283. //流水类型
  284. $capitalType = isset($remarkData['capitalType']) ? $remarkData['capitalType'] : null;
  285. if (isset($capitalType) == false) {
  286. noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
  287. util::end();
  288. }
  289. $currentPayWay = null;
  290. $connection = Yii::$app->db;
  291. $transaction = $connection->beginTransaction();
  292. try {
  293. if ($account_type == 'WECHAT') {
  294. $currentPayWay = dict::getDict('payWay', 'wxPay');
  295. } elseif ($account_type == 'ALIPAY') {
  296. $currentPayWay = dict::getDict('payWay', 'alipay');
  297. } else {
  298. noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
  299. util::end();
  300. }
  301. //支付成功后续流程
  302. $attach = 'merchant_no=' . $merchant_no;
  303. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  304. $transaction->commit();
  305. echo "SUCCESS";
  306. //解决重复通知
  307. $cacheKey = 'pay_success_notice_' . $orderSn;
  308. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  309. if (!empty($has)) {
  310. Yii::$app->end();
  311. }
  312. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  313. //客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
  314. if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
  315. $customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
  316. $customId = $customRecharge->customId ?? 0;
  317. $ghsId = $customRecharge->ghsId ?? 0;
  318. $ghs = GhsClass::getLockById($ghsId);
  319. $ghsShopId = $ghs->shopId ?? 0;
  320. $custom = CustomClass::getLockById($customId);
  321. $shop = ShopClass::getById($ghsShopId, true);
  322. // 销账已在 CustomRechargeClass::thirdPay 内按本次来款 FIFO 完成,勿再 useBalanceClear
  323. //充值销账通知
  324. WxMessageClass::customRechargeClearInform($shop, $customRecharge);
  325. }
  326. //零售线上结账通知
  327. if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
  328. $clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
  329. $customId = $clearInfo->customId ?? 0;
  330. $ghsShopId = $clearInfo->ghsShopId ?? 0;
  331. $ghsShop = ShopClass::getById($ghsShopId, true);
  332. $custom = CustomClass::getById($customId, true);
  333. if (!empty($custom) && !empty($ghsShop)) {
  334. WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  335. }
  336. }
  337. //零售采购成功后续流程
  338. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  339. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  340. $saleId = $cg->saleId ?? 0;
  341. $order = OrderClass::getById($saleId, true);
  342. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  343. GhsDeliveryOrderClass::payAfter($order);
  344. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔、镜中花卉,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  345. if (!empty($cg) && !empty($order)) {
  346. if (isset($cg->book) && $cg->book == 0) {
  347. $ghsShopId = $order->shopId ?? 0;
  348. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  349. if ($ext->orderFlow == 0) {
  350. PurchaseClass::confirmTake($cg);
  351. }
  352. }
  353. }
  354. //更新最后下单时间
  355. $customId = $order->customId ?? 0;
  356. $custom = CustomClass::getById($customId, true);
  357. $date = date("Y-m-d H:i:s");
  358. if (!empty($custom)) {
  359. $custom->recentExpend = $date;
  360. $custom->save();
  361. }
  362. $ghsId = $order->ghsId ?? 0;
  363. $ghs = GhsClass::getById($ghsId, true);
  364. if (!empty($ghs)) {
  365. $ghs->recentExpend = $date;
  366. $ghs->save();
  367. }
  368. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  369. if ($cg->transType != 5 && $cg->transType != 4) {
  370. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  371. $customId = $cg->customId ?? 0;
  372. $current = date("Y_m_d");
  373. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  374. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  375. }
  376. } else {
  377. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  378. $customId = $cg->customId ?? 0;
  379. if (isset($cg->sendType)) {
  380. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  381. $customId,
  382. $cg->sendType,
  383. $cg->sendCost ?? 0,
  384. $cg->packCost ?? 0
  385. );
  386. }
  387. }
  388. if (!empty($cg) && $cg->payStatus == 1) {
  389. //微信通知
  390. if (!empty($order)) {
  391. //订单生成时唤起在线打印
  392. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  393. //有几个地方要同步去修改
  394. if (getenv('YII_ENV') == 'production') {
  395. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  396. $mallOrderNoPrint = [10536, 44282, 26374];
  397. } else {
  398. $mallOrderNoPrint = [];
  399. }
  400. if (in_array($order->mainId, $mallOrderNoPrint)) {
  401. } else {
  402. $shopId = $order->shopId ?? 0;
  403. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  404. OrderClass::onlinePrint($order);
  405. if (isset($ext->printSn) && !empty($ext->printSn)) {
  406. $order->printNum += 1;
  407. $order->save();
  408. }
  409. if (getenv('YII_ENV') == 'production') {
  410. //福州我要花、花路鲜花批发、花镜打二次小票,有多处要修改搜索关键词tow_print
  411. $needTwoPrint = [7538, 36707, 76796, 94589];
  412. } else {
  413. $needTwoPrint = [];
  414. }
  415. if (in_array($order->mainId, $needTwoPrint)) {
  416. if ($order->mainId == 7538) {
  417. OrderClass::onlinePrint($order, 0);
  418. } else {
  419. OrderClass::onlinePrint($order);
  420. }
  421. if (isset($ext->printSn) && !empty($ext->printSn)) {
  422. $order->printNum += 1;
  423. $order->save();
  424. }
  425. }
  426. }
  427. }
  428. $cgShopId = $cg->shopId ?? 0;
  429. $cgShop = ShopClass::getById($cgShopId, true);
  430. if (!empty($cgShop)) {
  431. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  432. }
  433. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  434. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  435. ShopExtClass::ghsGatheringReport($order);
  436. }
  437. $shopId = $order->shopId ?? 0;
  438. $shop = ShopClass::getById($shopId, true);
  439. if (!empty($shop)) {
  440. //花店采购供货商端微信收到通知
  441. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  442. // $noticeText = json_encode(['orderId' => $saleId]);
  443. // $noticeKey = "hdCgNoticeGhs";
  444. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  445. GhsNotifyClass::newOrderNotify($saleId);
  446. //向供货商APP发通知
  447. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  448. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  449. // $push->ghsOrderMessage($shop, $cgShop, $order);
  450. }
  451. //花店采购供货商端APP收到通知
  452. //NoticeClass::ghsNewOrderNotice($order);
  453. }
  454. }
  455. }
  456. //散客下单买花,回调通知后,播报声音提示,这个方法本来不能写在这边要写在app-mall里的
  457. if ($capitalType == dict::getDict('capitalType', 'xhOrder', 'id')) {
  458. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  459. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  460. if (empty($has)) {
  461. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  462. $newOrder = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  463. if ($newOrder->onlinePay == 2) {
  464. //语音播报
  465. ShopExtClass::hdGatheringReport($newOrder);
  466. }
  467. }
  468. }
  469. exit();
  470. } catch (\Exception $e) {
  471. $transaction->rollBack();
  472. $msg = $e->getMessage();
  473. noticeUtil::push(" PayCallback 报错了 " . $currentPayWay . " capitalType:" . $capitalType . " orderSn:" . $orderSn . " totalFee:" . $totalFee . " 第三方id:" . $transactionId . " 原因:" . $msg, '15280215347');
  474. Yii::error("失败原因:" . $msg);
  475. }
  476. }
  477. //微信支付异步回调
  478. public function actionWxCallback()
  479. {
  480. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  481. if (empty($postStr)) {
  482. util::end();
  483. }
  484. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  485. if ($postObj->return_code != 'SUCCESS') {
  486. Yii::warning('return_code error:' . $postObj->return_code);
  487. util::end();
  488. }
  489. $orderSn = $postObj->out_trade_no;
  490. $total_fee = $postObj->total_fee;
  491. $totalFee = $total_fee / 100;
  492. $attach = $postObj->attach;
  493. $transactionId = $postObj->transaction_id ?? '';
  494. //接收流水类型、代金劵
  495. parse_str($attach);
  496. //流水类型
  497. $capitalType = isset($capitalType) ? $capitalType : null;
  498. if (isset($capitalType) == false) {
  499. Yii::warning('capitalType empty,orderSn:' . $orderSn);
  500. util::end();
  501. }
  502. $connection = Yii::$app->db;
  503. $transaction = $connection->beginTransaction();
  504. try {
  505. $wxPay = dict::getDict('payWay', 'wxPay');
  506. //支付成功后续流程
  507. payUtil::thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  508. $transaction->commit();
  509. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  510. //解决重复通知
  511. $cacheKey = 'pay_success_notice_' . $orderSn;
  512. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  513. if (!empty($has)) {
  514. Yii::$app->end();
  515. }
  516. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  517. // 花店续费(xhRenew)支付成功通知
  518. if ($capitalType == dict::getDict('capitalType', 'xhRenew', 'id')) {
  519. $renew = RenewClass::getByCondition(['orderSn' => $orderSn], true);
  520. $sjName = !empty($renew) ? (string) ($renew->sjName ?? '') : '';
  521. $shopName = !empty($renew) ? (string) ($renew->shopName ?? '') : '';
  522. $renewName = ($shopName === '' || $shopName === '首店')
  523. ? $sjName
  524. : trim($sjName . ' ' . $shopName);
  525. if ($renewName === '') {
  526. $renewName = (string) $orderSn;
  527. }
  528. $renewAmount = !empty($renew) ? ($renew->actPrice ?? $totalFee) : $totalFee;
  529. noticeUtil::push('零售花店:' . $renewName . ',续费金额:' . $renewAmount . ',续费成功', '15280215347');
  530. }
  531. //零售采购结账通知
  532. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  533. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  534. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  535. if ($cg->transType != 5 && $cg->transType != 4) {
  536. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  537. $customId = $cg->customId ?? 0;
  538. $current = date("Y_m_d");
  539. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  540. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  541. }
  542. } else {
  543. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  544. $customId = $cg->customId ?? 0;
  545. if (isset($cg->sendType)) {
  546. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  547. $customId,
  548. $cg->sendType,
  549. $cg->sendCost ?? 0,
  550. $cg->packCost ?? 0
  551. );
  552. }
  553. }
  554. if (!empty($cg) && $cg->payStatus == 1) {
  555. //微信通知
  556. $saleId = $cg->saleId ?? 0;
  557. $order = OrderClass::getById($saleId, true);
  558. if (!empty($order)) {
  559. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  560. GhsDeliveryOrderClass::payAfter($order);
  561. //订单生成时唤起在线打印
  562. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  563. //有几个地方要同步去修改
  564. if (getenv('YII_ENV') == 'production') {
  565. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  566. $mallOrderNoPrint = [10536, 44282, 26374];
  567. } else {
  568. $mallOrderNoPrint = [];
  569. }
  570. if (in_array($order->mainId, $mallOrderNoPrint)) {
  571. } else {
  572. OrderClass::onlinePrint($order);
  573. $order->printNum += 1;
  574. $order->save();
  575. }
  576. }
  577. $cgShopId = $cg->shopId ?? 0;
  578. $cgShop = ShopClass::getById($cgShopId, true);
  579. if (!empty($cgShop)) {
  580. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  581. }
  582. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  583. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  584. ShopExtClass::ghsGatheringReport($order);
  585. }
  586. $shopId = $order->shopId ?? 0;
  587. $shop = ShopClass::getById($shopId, true);
  588. if (!empty($shop)) {
  589. //花店采购供货商端微信收到通知
  590. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  591. // $noticeText = json_encode(['orderId' => $saleId]);
  592. // $noticeKey = "hdCgNoticeGhs";
  593. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  594. GhsNotifyClass::newOrderNotify($saleId);
  595. //向供货商端APP发通知
  596. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  597. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  598. // $push->ghsOrderMessage($shop, $cgShop, $order);
  599. }
  600. //花店采购供货商端APP收到通知
  601. //NoticeClass::ghsNewOrderNotice($order);
  602. }
  603. }
  604. }
  605. exit();
  606. } catch (\Exception $e) {
  607. $transaction->rollBack();
  608. Yii::error("失败原因:" . $e->getMessage());
  609. }
  610. }
  611. //微信退款结果通知
  612. public function actionWxRefundCallback()
  613. {
  614. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  615. if (empty($postStr)) {
  616. util::end();
  617. }
  618. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  619. if ($postObj->return_code != 'SUCCESS') {
  620. $msg = $postObj->return_msg ?? '';
  621. $text = '微信退款结果通知,报错了,报错内容:' . $msg;
  622. Yii::warning($text);
  623. noticeUtil::push($text, '15280215347');
  624. util::end();
  625. }
  626. //解密req_info
  627. $wx = WxOpenClass::getWxInfo();
  628. $req_info = $postObj->req_info ?? '';
  629. $key = $wx['wxPayKey'] ?? '';
  630. $xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
  631. $req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  632. $refund_status = $req_info_obj->refund_status ?? '';
  633. $orderSn = $req_info_obj->out_trade_no ?? '';
  634. $out_refund_no = $req_info_obj->out_refund_no ?? '';
  635. //订单总金额
  636. $total_fee = $req_info_obj->total_fee ?? 0.00;
  637. //申请退款金额
  638. //$refund_fee = $req_info_obj->refund_fee ?? 0.00;
  639. //退款金额
  640. $settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
  641. $new_total_fee = bcdiv($total_fee, 100, 2);
  642. $new_total_fee = floatval($new_total_fee);
  643. $new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
  644. $new_settlement_refund_fee = floatval($new_settlement_refund_fee);
  645. $connection = Yii::$app->db;
  646. $transaction = $connection->beginTransaction();
  647. $text = '';
  648. try {
  649. if ($refund_status == 'SUCCESS') {
  650. $cgRefund = CgRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
  651. if (!empty($cgRefund)) {
  652. $cgRefund->status = CgRefundClass::STATUS_COMPLETE;
  653. $cgRefund->save();
  654. $saleRefundId = $cgRefund->saleRefundId ?? 0;
  655. $saleRefund = RefundOrderClass::getById($saleRefundId, true);
  656. if (!empty($saleRefund)) {
  657. $saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
  658. $saleRefund->save();
  659. }
  660. }
  661. //$text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  662. } elseif ($refund_status == 'REFUNDCLOSE') {
  663. $text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  664. } else {
  665. $text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  666. }
  667. $transaction->commit();
  668. if (!empty($text)) {
  669. noticeUtil::push($text, '15280215347');
  670. }
  671. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  672. exit();
  673. } catch (\Exception $e) {
  674. $transaction->rollBack();
  675. Yii::error("失败原因:" . $e->getMessage());
  676. }
  677. }
  678. //采购后支付宝异步通知
  679. public function actionCgAliCallback()
  680. {
  681. header("Content-type: text/html; charset=utf-8");
  682. $aliWap = Yii::getAlias("@vendor/alipayWap");
  683. //商户订单号
  684. $orderSn = $_POST['out_trade_no'];
  685. // $aliPId = '2017041906821571';
  686. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFXBrmdKjAcRJ8Q7ZHUmzIqAV+IMV+RD4J5mZHeJgdAECgYEA8J+Hp1M6eYbT4CPLXa//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A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XqVc/twG016US5FNPV6fSllevsr0V020QemInO0+yJnTojSAfcayLroQId8Y3nPqVPpKMwvjvV7r50nGCCqXBtQsF4KITRzqrAoGAZBNyYNgBguRaEd1Sxw2gPmOUfvqiUCo6F4MJ+8xN8idn4FnaofcH8ic613PQPqpB/yYaxeqgIEfnvGY9ILXCuvbePfYqFmMwzALWvZ+v7uVKa2M7HstWCrq7O+m/lQFN/ut8ZnUDcBn4WwwHa/PjCYietetO2gpDRmAdSqrWGH8CgYBkwp+r6pkJzW60kHSZIlEKAe7oJMwLNC2ZqQ4MwGwzfBaH+E34kCuR8ZqYzyAIVOa/Nwi5By1Zvi1KzBwJmUUTJ3o7WCOE96EzSrmOZlqXNCwO/36Vh6dshhhE/birIlXJSP0xdzpBQy2ksyli9eGy8cdJ2Y72Wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  690. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  691. $config = [
  692. //应用ID,您的APP_ID
  693. 'app_id' => $aliPId,
  694. //商户私钥,您的原始格式RSA私钥
  695. 'merchant_private_key' => $aliKey,
  696. //异步通知地址
  697. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  698. //同步跳转
  699. 'return_url' => "",
  700. //编码格式
  701. 'charset' => "UTF-8",
  702. //签名方式
  703. 'sign_type' => "RSA2",
  704. //支付宝网关
  705. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  706. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  707. 'alipay_public_key' => $aliPublicKey,
  708. ];
  709. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  710. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  711. $arr = $_POST;
  712. $aliService = new \AlipayTradeService($config);
  713. $aliService->writeLog(var_export($_POST, true));
  714. $result = $aliService->check($arr);
  715. Yii::info('check:' . $result);
  716. if ($result == false) {
  717. //请不要修改
  718. echo "fail";
  719. util::end();
  720. }
  721. //验证成功后续
  722. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  723. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  724. $totalFee = $_POST['total_amount'] ?? '';
  725. $appId = $_POST['app_id'] ?? '';
  726. $attach = $_POST['passback_params'] ?? '';
  727. $attach = urldecode($attach);
  728. //接收流水类型、代金劵
  729. parse_str($attach);
  730. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  731. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  732. $RequestBuilder->setTradeNo($tradeNo);
  733. //$queryResult = $aliService->Query($RequestBuilder);
  734. //$aliId = $queryResult->buyer_user_id;
  735. //买家的支付宝帐号,不完整,带*号
  736. //$aliAccount = $queryResult->buyer_logon_id;
  737. if ($config['app_id'] != $appId) {
  738. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  739. util::end();
  740. }
  741. $connection = Yii::$app->db;
  742. $transaction = $connection->beginTransaction();
  743. try {
  744. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  745. $aliPay = dict::getDict('payWay', 'alipay');
  746. //支付成功后续流程
  747. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  748. $transaction->commit();
  749. //请不要修改
  750. echo "success";
  751. //解决重复通知
  752. $cacheKey = 'pay_success_notice_' . $orderSn;
  753. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  754. if (!empty($has)) {
  755. Yii::$app->end();
  756. }
  757. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  758. //零售采购通知
  759. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  760. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  761. if (!empty($cg) && $cg->payStatus == 1) {
  762. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  763. if ($cg->transType != 5 && $cg->transType != 4) {
  764. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  765. $customId = $cg->customId ?? 0;
  766. $current = date("Y_m_d");
  767. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  768. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  769. }
  770. } else {
  771. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  772. $customId = $cg->customId ?? 0;
  773. if (isset($cg->sendType)) {
  774. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  775. $customId,
  776. $cg->sendType,
  777. $cg->sendCost ?? 0,
  778. $cg->packCost ?? 0
  779. );
  780. }
  781. }
  782. //微信通知
  783. $saleId = $cg->saleId ?? 0;
  784. $order = OrderClass::getById($saleId, true);
  785. if (!empty($order)) {
  786. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  787. GhsDeliveryOrderClass::payAfter($order);
  788. //订单生成时唤起在线打印
  789. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  790. //有几个地方要同步去修改
  791. if (getenv('YII_ENV') == 'production') {
  792. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  793. $mallOrderNoPrint = [10536, 44282, 26374];
  794. } else {
  795. $mallOrderNoPrint = [];
  796. }
  797. if (in_array($order->mainId, $mallOrderNoPrint)) {
  798. } else {
  799. OrderClass::onlinePrint($order);
  800. $order->printNum += 1;
  801. $order->save();
  802. }
  803. }
  804. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  805. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  806. ShopExtClass::ghsGatheringReport($order);
  807. }
  808. $cgShopId = $cg->shopId ?? 0;
  809. $cgShop = ShopClass::getById($cgShopId, true);
  810. if (!empty($cgShop)) {
  811. NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  812. }
  813. $shopId = $order->shopId ?? 0;
  814. $shop = ShopClass::getById($shopId, true);
  815. if (!empty($shop)) {
  816. //花店采购供货商端微信收到通知
  817. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  818. $noticeText = json_encode(['orderId' => $saleId]);
  819. $noticeKey = "hdCgNoticeGhs";
  820. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  821. GhsNotifyClass::newOrderNotify($saleId);
  822. //向供货商端APP发通知
  823. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  824. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  825. // $push->ghsOrderMessage($shop, $cgShop, $order);
  826. }
  827. //花店采购供货商端APP收到通知
  828. //NoticeClass::ghsNewOrderNotice($order);
  829. }
  830. }
  831. }
  832. }
  833. exit();
  834. } catch (\Exception $e) {
  835. $transaction->rollBack();
  836. Yii::error("失败原因:" . $e->getMessage());
  837. }
  838. }
  839. //支付宝异步通知
  840. public function actionAliCallback()
  841. {
  842. header("Content-type: text/html; charset=utf-8");
  843. $aliWap = Yii::getAlias("@vendor/alipayWap");
  844. //商户订单号
  845. $orderSn = $_POST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ILXCuvbePfYqFmMwzALWvZ+v7uVKa2M7HstWCrq7O+m/lQFN/ut8ZnUDcBn4WwwHa/PjCYietetO2gpDRmAdSqrWGH8CgYBkwp+r6pkJzW60kHSZIlEKAe7oJMwLNC2ZqQ4MwGwzfBaH+E34kCuR8ZqYzyAIVOa/Nwi5By1Zvi1KzBwJmUUTJ3o7WCOE96EzSrmOZlqXNCwO/36Vh6dshhhE/birIlXJSP0xdzpBQy2ksyli9eGy8cdJ2Y72Wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  851. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  852. $config = [
  853. //应用ID,您的APP_ID
  854. 'app_id' => $aliPId,
  855. //商户私钥,您的原始格式RSA私钥
  856. 'merchant_private_key' => $aliKey,
  857. //异步通知地址
  858. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  859. //同步跳转
  860. 'return_url' => "",
  861. //编码格式
  862. 'charset' => "UTF-8",
  863. //签名方式
  864. 'sign_type' => "RSA2",
  865. //支付宝网关
  866. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  867. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  868. 'alipay_public_key' => $aliPublicKey,
  869. ];
  870. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  871. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  872. $arr = $_POST;
  873. $aliService = new \AlipayTradeService($config);
  874. $aliService->writeLog(var_export($_POST, true));
  875. $result = $aliService->check($arr);
  876. Yii::info('check:' . $result);
  877. if ($result == false) {
  878. //请不要修改
  879. echo "fail";
  880. util::end();
  881. }
  882. //验证成功后续
  883. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  884. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  885. $totalFee = $_POST['total_amount'] ?? '';
  886. $appId = $_POST['app_id'] ?? '';
  887. $attach = $_POST['passback_params'] ?? '';
  888. $attach = urldecode($attach);
  889. //接收流水类型、代金劵
  890. parse_str($attach);
  891. //流水类型
  892. $capitalType = isset($capitalType) ? $capitalType : null;
  893. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  894. $RequestBuilder->setTradeNo($tradeNo);
  895. //$queryResult = $aliService->Query($RequestBuilder);
  896. //$aliId = $queryResult->buyer_user_id;
  897. //买家的支付宝帐号,不完整,带*号
  898. //$aliAccount = $queryResult->buyer_logon_id;
  899. if (isset($capitalType) == false) {
  900. Yii::warning('capitalType empty, orderSn:' . $orderSn);
  901. util::end();
  902. }
  903. if ($config['app_id'] != $appId) {
  904. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  905. util::end();
  906. }
  907. $connection = Yii::$app->db;
  908. $transaction = $connection->beginTransaction();
  909. try {
  910. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  911. $aliPay = dict::getDict('payWay', 'alipay');
  912. //支付成功后续流程
  913. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  914. $transaction->commit();
  915. }
  916. //请不要修改
  917. echo "success";
  918. exit();
  919. } catch (\Exception $e) {
  920. $transaction->rollBack();
  921. Yii::error("失败原因:" . $e->getMessage());
  922. }
  923. }
  924. }