NoticeController.php 55 KB

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