NoticeController.php 53 KB

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