NoticeController.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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. noticeUtil::push('花店:' . $renewName . ',续费成功', '15280215347');
  529. }
  530. //零售采购结账通知
  531. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  532. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  533. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  534. if ($cg->transType != 5 && $cg->transType != 4) {
  535. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  536. $customId = $cg->customId ?? 0;
  537. $current = date("Y_m_d");
  538. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  539. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  540. }
  541. } else {
  542. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  543. $customId = $cg->customId ?? 0;
  544. if (isset($cg->sendType)) {
  545. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  546. $customId,
  547. $cg->sendType,
  548. $cg->sendCost ?? 0,
  549. $cg->packCost ?? 0
  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//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA4NRPxmXvIjjmLb1Ft1qwHuy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nGCCqXBtQsF4KITRzqrAoGAZBNyYNgBguRaEd1Sxw2gPmOUfvqiUCo6F4MJ+8xN8idn4FnaofcH8ic613PQPqpB/yYaxeqgIEfnvGY9ILXCuvbePfYqFmMwzALWvZ+v7uVKa2M7HstWCrq7O+m/lQFN/ut8ZnUDcBn4WwwHa/PjCYietetO2gpDRmAdSqrWGH8CgYBkwp+r6pkJzW60kHSZIlEKAe7oJMwLNC2ZqQ4MwGwzfBaH+E34kCuR8ZqYzyAIVOa/Nwi5By1Zvi1KzBwJmUUTJ3o7WCOE96EzSrmOZlqXNCwO/36Vh6dshhhE/birIlXJSP0xdzpBQy2ksyli9eGy8cdJ2Y72Wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  689. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/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. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  771. $customId = $cg->customId ?? 0;
  772. if (isset($cg->sendType)) {
  773. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  774. $customId,
  775. $cg->sendType,
  776. $cg->sendCost ?? 0,
  777. $cg->packCost ?? 0
  778. );
  779. }
  780. }
  781. //微信通知
  782. $saleId = $cg->saleId ?? 0;
  783. $order = OrderClass::getById($saleId, true);
  784. if (!empty($order)) {
  785. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  786. GhsDeliveryOrderClass::payAfter($order);
  787. //订单生成时唤起在线打印
  788. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  789. //有几个地方要同步去修改
  790. if (getenv('YII_ENV') == 'production') {
  791. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  792. $mallOrderNoPrint = [10536, 44282, 26374];
  793. } else {
  794. $mallOrderNoPrint = [];
  795. }
  796. if (in_array($order->mainId, $mallOrderNoPrint)) {
  797. } else {
  798. OrderClass::onlinePrint($order);
  799. $order->printNum += 1;
  800. $order->save();
  801. }
  802. }
  803. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  804. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  805. ShopExtClass::ghsGatheringReport($order);
  806. }
  807. $cgShopId = $cg->shopId ?? 0;
  808. $cgShop = ShopClass::getById($cgShopId, true);
  809. if (!empty($cgShop)) {
  810. NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  811. }
  812. $shopId = $order->shopId ?? 0;
  813. $shop = ShopClass::getById($shopId, true);
  814. if (!empty($shop)) {
  815. //花店采购供货商端微信收到通知
  816. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  817. $noticeText = json_encode(['orderId' => $saleId]);
  818. $noticeKey = "hdCgNoticeGhs";
  819. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  820. GhsNotifyClass::newOrderNotify($saleId);
  821. //向供货商端APP发通知
  822. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  823. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  824. // $push->ghsOrderMessage($shop, $cgShop, $order);
  825. }
  826. //花店采购供货商端APP收到通知
  827. //NoticeClass::ghsNewOrderNotice($order);
  828. }
  829. }
  830. }
  831. }
  832. exit();
  833. } catch (\Exception $e) {
  834. $transaction->rollBack();
  835. Yii::error("失败原因:" . $e->getMessage());
  836. }
  837. }
  838. //支付宝异步通知
  839. public function actionAliCallback()
  840. {
  841. header("Content-type: text/html; charset=utf-8");
  842. $aliWap = Yii::getAlias("@vendor/alipayWap");
  843. //商户订单号
  844. $orderSn = $_POST['out_trade_no'];
  845. // $aliPId = '2017041906821571';
  846. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90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/PjCYietetO2gpDRmAdSqrWGH8CgYBkwp+r6pkJzW60kHSZIlEKAe7oJMwLNC2ZqQ4MwGwzfBaH+E34kCuR8ZqYzyAIVOa/Nwi5By1Zvi1KzBwJmUUTJ3o7WCOE96EzSrmOZlqXNCwO/36Vh6dshhhE/birIlXJSP0xdzpBQy2ksyli9eGy8cdJ2Y72Wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  850. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  851. $config = [
  852. //应用ID,您的APP_ID
  853. 'app_id' => $aliPId,
  854. //商户私钥,您的原始格式RSA私钥
  855. 'merchant_private_key' => $aliKey,
  856. //异步通知地址
  857. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  858. //同步跳转
  859. 'return_url' => "",
  860. //编码格式
  861. 'charset' => "UTF-8",
  862. //签名方式
  863. 'sign_type' => "RSA2",
  864. //支付宝网关
  865. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  866. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  867. 'alipay_public_key' => $aliPublicKey,
  868. ];
  869. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  870. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  871. $arr = $_POST;
  872. $aliService = new \AlipayTradeService($config);
  873. $aliService->writeLog(var_export($_POST, true));
  874. $result = $aliService->check($arr);
  875. Yii::info('check:' . $result);
  876. if ($result == false) {
  877. //请不要修改
  878. echo "fail";
  879. util::end();
  880. }
  881. //验证成功后续
  882. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  883. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  884. $totalFee = $_POST['total_amount'] ?? '';
  885. $appId = $_POST['app_id'] ?? '';
  886. $attach = $_POST['passback_params'] ?? '';
  887. $attach = urldecode($attach);
  888. //接收流水类型、代金劵
  889. parse_str($attach);
  890. //流水类型
  891. $capitalType = isset($capitalType) ? $capitalType : null;
  892. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  893. $RequestBuilder->setTradeNo($tradeNo);
  894. //$queryResult = $aliService->Query($RequestBuilder);
  895. //$aliId = $queryResult->buyer_user_id;
  896. //买家的支付宝帐号,不完整,带*号
  897. //$aliAccount = $queryResult->buyer_logon_id;
  898. if (isset($capitalType) == false) {
  899. Yii::warning('capitalType empty, orderSn:' . $orderSn);
  900. util::end();
  901. }
  902. if ($config['app_id'] != $appId) {
  903. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  904. util::end();
  905. }
  906. $connection = Yii::$app->db;
  907. $transaction = $connection->beginTransaction();
  908. try {
  909. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  910. $aliPay = dict::getDict('payWay', 'alipay');
  911. //支付成功后续流程
  912. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  913. $transaction->commit();
  914. }
  915. //请不要修改
  916. echo "success";
  917. exit();
  918. } catch (\Exception $e) {
  919. $transaction->rollBack();
  920. Yii::error("失败原因:" . $e->getMessage());
  921. }
  922. }
  923. }