NoticeController.php 56 KB

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