NoticeController.php 55 KB

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