AllinpayNotifyController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\common\controllers;
  8. use app\models\ReOrder;
  9. use app\modules\common\models\NotifyForm;
  10. use app\utils\OrderNo;
  11. use app\utils\Wechat\Wechat;
  12. use app\utils\Wechat\WechatProfit;
  13. use app\utils\Wechat\WechatShare;
  14. use EasyWeChat\Kernel\Exceptions\Exception;
  15. use EasyWeChat\Kernel\BaseClient;
  16. use yii\web\Controller;
  17. use app\utils\IotCloudHelper;
  18. use app\models\Store;
  19. use app\models\OrderUnion;
  20. use app\models\Order;
  21. use app\models\WechatConfig;
  22. use app\utils\Adapay\Adapay;
  23. use app\utils\Adapay\AdapayV2;
  24. use app\utils\Allinpay\Allinpay;
  25. use app\utils\Allinpay\AppUtil;
  26. /**
  27. * 微信回调类
  28. * Class WechatNotifyController
  29. * @package app\modules\common\controllers
  30. */
  31. class AllinpayNotifyController extends Controller
  32. {
  33. public static $plugins = [
  34. 'SC' => '\app\plugins\scanCodePay\controllers\CallbackController::execute'
  35. ];
  36. public function actionTest() {
  37. $order = Order::findOne(['order_no' => 'ML20230522140611637863']);
  38. \app\utils\Adapay\Adapay::paymentConfirmQueryList($order);die;
  39. $out_trade_no = input_params('out_trade_no');
  40. $data = [
  41. 'order_no' => $out_trade_no,
  42. ];
  43. $this->notify($data, 317);
  44. }
  45. /**
  46. * 入口文件
  47. * @throws \Exception
  48. */
  49. public function actionIndex() {
  50. $store_id = get_params('store_id');
  51. \Yii::error(['Allinpay NOTIFY INDEX <==========> ', all_params()]);
  52. debug_log([all_params()], __CLASS__ . '.log');
  53. $post = all_params();
  54. foreach($post as $key=>$val) {//动态遍历获取所有收到的参数,此步非常关键,因为收银宝以后可能会加字段,动态获取可以兼容由于收银宝加字段而引起的签名异常
  55. $post[$key] = $val;
  56. }
  57. if(count($post)<1){//如果参数为空,则不进行处理
  58. echo "error";
  59. \Yii::$app->end();
  60. }
  61. if(!AppUtil::ValidSign($post)){
  62. echo "error";
  63. \Yii::$app->end();
  64. }
  65. // $post = [
  66. // 'created_time' => '1684142110',
  67. // 'data' => "{\"app_id\":\"app_9aa823b9-d959-4307-a931-23ba8780f9aa\",\"created_time\":\"20230515171510\",\"description\":\"\",\"end_time\":\"20230515171620\",\"expend\":{\"bank_type\":\"CMB\",\"open_id\":\"o8jhotynrwBGRepP0IKKJ-5zuykY\",\"sub_open_id\":\"oNiCd4gweWf2Irg2K5WfTFWFGEts\"},\"fee_amt\":\"0.00\",\"id\":\"002212023051517151010504112702133735424\",\"order_no\":\"ML20230515171505384756\",\"out_trans_id\":\"4200001875202305153971501223\",\"party_order_id\":\"02212305156211026504784\",\"pay_amt\":\"0.01\",\"pay_channel\":\"wx_lite\",\"real_amt\":\"0.01\",\"share_eq\":\"Y\",\"status\":\"succeeded\",\"wx_user_id\":\"\"}",
  68. // 'prod_mode' => 'true',
  69. // 'sign' => 'ZaWpAQfqOzgRE6OUYDY/pt8jQRnMJ1K1YQkCukLRVlS8N9MycpP022pbaTvWovJY3a+do4lyWsFaKS16CfXcdAj1/4zHTh4YDO7PLYMf3c86cna/VrhuD9aIedPVUe0tkdarODPS7M3W3lt90iPRJ8LsuvLQjrD+go2hXr6NKak=',
  70. // 'id' => '002210504112997909880832',
  71. // 'type' => 'payment.succeeded',
  72. // 'app_id' => 'app_9aa823b9-d959-4307-a931-23ba8780f9aa',
  73. // 'object' => 'payment',
  74. //];
  75. if(in_array($post['trxcode'], ['VSP681', 'VSP501', 'VSP511'])){
  76. $post['order_no'] = $post['cusorderid'];
  77. // $orderNoHead = substr($post['cusorderid'], 0, 2);
  78. $this->notify($post, $store_id);
  79. return;
  80. }
  81. }
  82. /**
  83. * @param $data
  84. * @param $store_id
  85. * 回调逻辑处理
  86. */
  87. private function notify($data, $store_id) {
  88. \Yii::error(['Allinpay NOTIFY <==========> ', $store_id, $data]);
  89. try {
  90. $notify = new NotifyForm();
  91. if(in_array($data['trxcode'], ['VSP681', 'VSP501'])){
  92. $notify->pay_type = Order::PAY_TYPE_ALLINPAY_WX;
  93. $channelName = '微信';
  94. }
  95. if(in_array($data['trxcode'], ['VSP511'])){
  96. $notify->pay_type = Order::PAY_TYPE_ALLINPAY_ALIPAY;
  97. $channelName = '支付宝';
  98. }
  99. if (isset($data['trxamt'])) {
  100. $store = Store::findOne($store_id);
  101. if ($store && !empty($store->device_name)) {
  102. $total_fee = $data['trxamt'];
  103. IotCloudHelper::sendMessage($store_id, '{"cmd":"voice","msg":"' . $channelName . '收款'.$total_fee.'元","msgid":"'.$store_id. time() .'"}');
  104. }
  105. }
  106. $orderNoHead = substr($data['order_no'], 0, 2);
  107. $message = array_merge([
  108. 'out_trade_no' => $data['order_no'],
  109. 'transaction_id' => '',
  110. 'out_batch_no' => '',
  111. 'batch_status' => '',
  112. 'fail_count' => '',
  113. 'batch_status' => '',
  114. 'batch_status' => '',
  115. ], $data);
  116. switch ($orderNoHead) {
  117. case 'UN':
  118. // 合并支付的订单
  119. $notify->UnionOrderNotify($message);
  120. break;
  121. case 'RG':
  122. // 充值订单
  123. $notify->RechargeOrderNotify($message);
  124. case OrderNo::INTEGRAL_RECHARGE:
  125. // 充值订单
  126. $notify->IntegralRechargeOrderNotify($message);
  127. break;
  128. case 'LV':
  129. // 会员购买
  130. $notify->LevelOrderNotify($message);
  131. break;
  132. case 'ML':
  133. // 商城订单
  134. $notify->MallOrderNotify($message);
  135. break;
  136. case 'SC':
  137. // 当面付订单
  138. $notify->ScanOrderNotify($message);
  139. break;
  140. case 'PC':
  141. // 联盟佣金提现订单
  142. $notify->saasProfitCash($message);
  143. break;
  144. case 'FO':
  145. // 点餐订单
  146. $notify->FoodNotify($message);
  147. break;
  148. case 'SG':
  149. // 店铺充值订单
  150. $notify->StoreReOrderNotify($message);
  151. break;
  152. case 'AM':
  153. //商盟会员卡订单
  154. $notify->BusinessMemberOrderNotify($message);
  155. break;
  156. case 'AL':
  157. //商盟会员购物订单
  158. $notify->BusinessNotify($message);
  159. break;
  160. case 'AD':
  161. // 认养费用
  162. $notify->AdoptCostOrderNotify($message);
  163. break;
  164. case 'AP':
  165. // 采购员订单
  166. $notify->APOrderNotify($message);
  167. break;
  168. case 'PR':
  169. \Yii::error([__METHOD__, 'PROrderNotify', $message]);
  170. // 采购员充值
  171. $notify->PROrderNotify($message);
  172. break;
  173. case 'LP':
  174. // 联盟券充值
  175. $notify->LPorderNotify($message);
  176. break;
  177. case 'PT':
  178. // 充值订单
  179. $notify->ptActivityOrderNotify($message);
  180. break;
  181. default:
  182. break;
  183. }
  184. return true; // 返回处理完成
  185. } catch (\Exception $e) {
  186. \Yii::warning(['ADAPAY NOTIFY EXCEPTION <==========> ', $e->getMessage()]);
  187. }
  188. }
  189. }