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