YunstNotifyController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 app\utils\yunst\src\Config\conf;
  15. use app\utils\yunst\src\Log\Log;
  16. use app\utils\yunst\src\SDK\yunClient;
  17. use EasyWeChat\Kernel\Exceptions\Exception;
  18. use EasyWeChat\Kernel\BaseClient;
  19. use yii\web\Controller;
  20. use app\utils\IotCloudHelper;
  21. use app\models\Store;
  22. use app\models\OrderUnion;
  23. use app\models\Order;
  24. use app\models\WechatConfig;
  25. use app\utils\Adapay\Adapay;
  26. use app\utils\Adapay\AdapayV2;
  27. /**
  28. * 微信回调类
  29. * Class WechatNotifyController
  30. * @package app\modules\common\controllers
  31. */
  32. class YunstNotifyController extends Controller
  33. {
  34. public static $plugins = [
  35. 'SC' => '\app\plugins\scanCodePay\controllers\CallbackController::execute'
  36. ];
  37. private $logIns;
  38. private $config;
  39. // public function __construct(){
  40. // $this->logIns = Log::getInstance();
  41. // $this->config = conf::getInstance();
  42. // $this->config->loadConf(\Yii::$app->basePath.'/utils/yunst/src/Config/config.php');
  43. //// dd($this->config);
  44. //
  45. // }
  46. //
  47. // public function actionTest() {
  48. // $order = Order::findOne(['order_no' => 'ML20230522140611637863']);
  49. // \app\utils\Adapay\Adapay::paymentConfirmQueryList($order);die;
  50. // $out_trade_no = input_params('out_trade_no');
  51. // $data = [
  52. // 'order_no' => $out_trade_no,
  53. // ];
  54. // $this->notify($data, 317);
  55. // }
  56. // public function actionH5() {
  57. // $this->redirect(\Yii::$app->request->hostInfo . '/h5/static/h5/webview.html');
  58. //// $this->redirect('http://192.168.0.159:8080/h5/static/h5/webview.html');
  59. // }
  60. /**
  61. * 入口文件
  62. * @throws \Exception
  63. */
  64. public function actionIndex() {
  65. $store_id = get_params('store_id');
  66. debug_log('yunst支付回调', 'yunst.log');
  67. debug_log($store_id, 'yunst.log');
  68. $post = all_params();
  69. debug_log('来到yunst支付回调', 'yunst.log');
  70. debug_log($post, 'yunst.log');
  71. $this->logIns = Log::getInstance();
  72. $this->config = conf::getInstance();
  73. $this->config->loadConf(\Yii::$app->basePath.'/utils/yunst/src/Config/config.php');
  74. $yunClient = new yunClient();
  75. $res = $yunClient->checkPost($post);
  76. // $info = '{"store_id":"6","appId":"1546394428142972930","bizContent":"{\"acct\":\"opn0buLZJ-LoSHpt0MuX0IAdRW5Y\",\"accttype\":\"99\",\"bankcode\":\"0000\",\"chnltrxid\":\"4200002110202401233570380768\",\"cmid\":\"234192503\",\"cusid\":\"552290073948XTG\",\"cusorderid\":\"SC20240123145958400674\",\"fee\":\"0\",\"initamt\":\"1\",\"outtrxid\":\"SC20240123145958400674\",\"paytime\":\"20240123150018\",\"termrefnum\":\"4200002110202401233570380768\",\"termtraceno\":\"0\",\"trxamt\":\"1\",\"trxcode\":\"VSP501\",\"trxdate\":\"20240123\",\"trxid\":\"240123116400032459\",\"trxstatus\":\"0000\"}","charset":"utf-8","notifyId":"1749688491262464001","notifyTime":"2024-01-23 15:00:18","notifyType":"allinpay.isvyunst.transaction.unitorder.pay","sign":"kW94Ndbt4Y3MU\/f85HxXymIfq1GWtr+hxFqupPG6slZ7rooA76QUgpCZEpOv0gi8DR80QK4GCdhLvpEHlOl1nws1mMiNUN7CKXfw3gmUqGNR3OykELbDXenfWppi2T1q7D\/8yQyYphJwCyaHfdw3wViVN32fh7m0EkKdCMONXzS1mk5u7h1s4kjeCTyXltWjP2yfJXErc4YIqpnA4c0\/gHn5rP6n\/uIB\/P6TfZAQRCL3NBQLdoqgYkvq+e+NO861BPABcl+t6X0fQBzEhhGJGZ4Rhtki59N7rFcPz82YS+coAMJIeQcke0MwXOYNydEJp8O5y6E4SwbS+V17uoq\/rA==","signType":"SHA256withRSA","version":"1.0"}';
  77. // $post = json_decode($info,true);
  78. // echo '<pre>';
  79. // print_r(json_decode($post['bizContent'],true));die();
  80. //验证签名成功
  81. if ($res){
  82. debug_log('验证签名成功', 'yunst.log');
  83. $bizContent = json_decode($post['bizContent'],true);
  84. debug_log($bizContent, 'yunst.log');
  85. if(isset($bizContent) && $bizContent['trxstatus'] == "0000"){
  86. $this->notify($bizContent, $store_id, 1);
  87. die;
  88. }
  89. // if(empty($post['data'])){
  90. // throw new \Exception('data参数为空');
  91. // }
  92. }
  93. // var_dump($post['data']);
  94. // $data = json_decode($post['data'], true);
  95. // if($data['status'] !== 'succeeded'){
  96. // return;
  97. // }
  98. // $orderNoHead = substr($data['order_no'], 0, 2);
  99. // $this->notify($data, $store_id);
  100. }
  101. /**
  102. * @param $data
  103. * @param $store_id
  104. * 回调逻辑处理
  105. */
  106. private function notify($data, $store_id, $isV2 = false) {
  107. \Yii::error(['YUNST NOTIFY INDEX <==========> ', $store_id, $data]);
  108. try {
  109. $notify = new NotifyForm();
  110. if($isV2){
  111. // $data = [
  112. // 'store_id' => '84',
  113. // 'resp_desc' => '交易成功[000]',
  114. // 'resp_code' => '00000000',
  115. // 'sign' => 'p+Ys1lpCaEKhDON/+Bxj9fvLPAd/Xi54JmbQFs63yiT9jTM9SDV4TA5I6wssEGLT5WYdJFSj/yd5qz8b5SEIt6kw5bAeGpvcpY7YUb2Ffq/XY/1+HnXf+xESD9bUUgL7tNGom0d8MoLzsAEzS9lBiazJFuV7ueBQtKd2RpWSTiSt42JNQ2iMGvAsjGXc+oOfIqKu483LZVCuv/V7Ce5qkq8qEzQ1b/Vt1v01GYQugUdCvkqKagUnxq8/rTpjcOzUPWtGYVUeH3XBdeozZdv20TtJ/6dAnQBMVw6Ny1SfTLuZ5S+6gI4QINdkJSPXx7AmgcuTZPkszrGlN1lifEAcOA==',
  116. // 'resp_data' => '{"acct_date":"20230922","acct_id":"F01813225","acct_split_bunch":{"acct_infos":[{"acct_id":"F01813225","div_amt":"0.01","huifu_id":"6666000139854172"}],"fee_acct_id":"F01813225","fee_amt":"0.00","fee_huifu_id":"6666000139854172"},"acct_stat":"S","avoid_sms_flag":"","bagent_id":"6666000131001671","bagent_name":"招商银行","bank_code":"00","bank_desc":"成功[0000000]","bank_extend_param":{"bank_id":"03080000","pyer_acct_id":"622588******2233","pyer_acct_nm":"刘晓波"},"bank_id":"03080000","bank_message":"成功[0000000]","bank_name":"招商银行","base_acct_id":"F01813225","channel_type":"U","combinedpay_data":[],"combinedpay_fee_amt":"0.00","debit_flag":"D","debit_type":"0","delay_acct_flag":"N","div_flag":"0","end_time":"20230922171457","fee_amount":"0.00","fee_amt":"0.00","fee_flag":2,"fee_rec_type":"1","fee_type":"INNER","gate_id":"SA","hf_seq_id":"00470topo1A230922171302P644ac136a1f00000","huifu_id":"6666000139854172","is_delay_acct":"0","is_div":"0","mer_name":"瑞峰奇会科技(重庆)有限公司","mer_ord_id":"20230922ML20230922170657200680","mypaytsf_discount":"0.00","need_big_object":true,"notify_type":2,"order_type":"P","org_auth_no":"","org_huifu_seq_id":"","org_trans_date":"","pay_card_id":"622588******2233","pay_scene":"","product_id":"EDUARK","req_date":"20230922","req_seq_id":"ML20230922170657200680","resp_code":"00000000","resp_desc":"交易成功","risk_check_data":{"ip_addr":"8.140.144.252"},"risk_check_info":{"client_ip":"8.140.144.252"},"settlement_amt":"0.01","sub_resp_code":"00000000","sub_resp_desc":"交易成功","sys_id":"6666000139854172","trans_amt":"0.01","trans_date":"20230922","trans_order_info":{"acct_finish_time":1695374097000,"acct_id":"F01813225","acct_stat":"S","acct_trans_date":"20230922","agent_id":"6666000131001671","bagent_id":"6666000131001671","bagent_name":"蒋永春","bank_id":"03080000","bank_name":"招商银行","bank_resp_code":"00","bank_resp_desc":"成功[0000000]","card_bank_id":"03080000","card_channel_type":"","card_sign":"","cash_req_date":"20230922","cash_resp_code":"00000001","cash_resp_desc":"部分成功","cashier_version":"V2","channel_finish_time":1695374097000,"channel_stat":"S","channel_type":"U","check_cash_flag":"I","close_trans_stat":"","create_time":1695374015000,"creator":"","credit_fee_amt":0.00,"credit_type":"","db_unit":"1","dc_type":"D","debit_fee_amt":0.00,"double_limit_amt":0.00,"fee_acct_id":"F01813225","fee_amt":0.00,"fee_flag":2,"fee_formula":"","fee_huifu_id":"6666000139854172","fee_real_acct_id":"F01813225","fee_real_cust_id":"6666000139854172","fee_rec_type":1,"fee_source":"\'SERVER\'","fee_split_type":"","gate_id":"SA","goods_desc":"Apple/苹果 AirPods (第三","hf_seq_id":"00470topo1A230922171302P644ac136a1f00000","huifu_id":"6666000139854172","icc_data":"","id":3922522470,"is_acct_div":0,"is_acct_div_param":0,"is_delay_acct":0,"is_deleted":0,"is_route":"","iss_inst_id":"","maze_bg_date":"","maze_bg_seq_id":"","maze_pnr_dev_id":"","maze_resp_code":"","maze_resp_desc":"","mcc":"","mer_name":"瑞峰奇会科技(重庆)有限公司","mer_ord_id":"20230922ML20230922170657200680","modifier":"","modify_time":1695374097000,"mypaytsf_discount":0.00,"ord_amt":0.01,"ord_id":"20230922171335topo1_Ait527545501","org_acct_id":"F01813225","org_auth_no":"","org_huifu_seq_id":"","org_trans_date":"","pa_mer_id":"SSP001","pay_card_id":"622588******2233","pay_card_id_enc":"#011gGHN02tS7uIxBegcfZneJg==","pay_channel":"","pay_scene":"","pay_type":"QUICK_PAY","product_id":"EDUARK","real_acct_id":"F01813225","real_cust_id":"6666000139854172","real_gate_id":"SA","real_pay_type":"3003","ref_amt":0.01,"ref_cnt":0,"ref_fee_amt":0.00,"region_id":"topo1_A","req_date":"20230922","req_seq_id":"ML20230922170657200680","settle_amt":0.01,"settle_trans_stat":"","sn_code":"","subsidy_amt":0.00,"subsidy_ref_amt":0.00,"sys_id":"6666000139854172","sys_trace_audit_num":"","term_div_coupon_type":3,"time_expire":"20230923051302","trans_date":"20230922","trans_finish_time":1695374097000,"trans_notify_url":"virgo://https://chidian.cyyvip.com/index.php/adapay/notify/84","trans_stat":"S","trans_type":"3004","un_scene_info":"","unconfirm_amt":0.01,"unconfirm_fee_amt":0.00,"version":4},"trans_stat":"S","trans_time":"171335","trans_type":"QUICK_PAY","ts_encash_detail":[],"user_huifu_id":"6666000140145254"}',
  117. // ];
  118. debug_log('走到支付回调', 'yunst.log');
  119. $notify = new NotifyForm();
  120. $orderNoHead = substr($data['outtrxid'], 0, 2);
  121. $notify->pay_type = Order::PAY_TYPE_YUNST_WECHAT_PAY;
  122. $notify->is_yunst = 1;
  123. $channelName = '微信';
  124. // $message = array_merge([
  125. // 'out_trade_no' => $data['outtrxid'],
  126. // 'transaction_id' => '',
  127. // 'out_batch_no' => '',
  128. // 'batch_status' => '',
  129. // 'fail_count' => '',
  130. // 'batch_status' => '',
  131. // 'batch_status' => '',
  132. // ], $data);
  133. if (isset($data['trxamt'])) {
  134. $store = Store::findOne($store_id);
  135. if ($store && !empty($store->device_name)) {
  136. // $total_fee = $data['trxamt'];
  137. $total_fee = round($data['trxamt'] / 100, 2);
  138. $aaa = IotCloudHelper::sendMessage($store_id, '{"cmd":"voice","msg":"' . '微信收款'.$total_fee.'元","msgid":"'.$data['trxid'] .'"}');
  139. }
  140. }
  141. $orderNoHead = substr($data['outtrxid'], 0, 2);
  142. $message = array_merge([
  143. 'out_trade_no' => $data['outtrxid'],
  144. 'transaction_id' => $data['trxid'],
  145. 'out_batch_no' => '',
  146. 'batch_status' => '',
  147. 'fail_count' => '',
  148. ], $data);
  149. }else{
  150. if(strstr($data['pay_channel'], 'wx_')){
  151. $notify->pay_type = Order::PAY_TYPE_YUNST_WECHAT_PAY;
  152. $channelName = '微信';
  153. }
  154. if(strstr($data['pay_channel'], 'alipay')){
  155. $notify->pay_type = Order::PAY_TYPE_YUNST_ALI_PAY;
  156. $channelName = '支付宝';
  157. }
  158. if (isset($data['pay_amt'])) {
  159. $store = Store::findOne($store_id);
  160. if ($store && !empty($store->device_name)) {
  161. $total_fee = $data['pay_amt'];
  162. IotCloudHelper::sendMessage($store_id, '{"cmd":"voice","msg":"' . $channelName . '收款'.$total_fee.'元","msgid":"'.$store_id. time() .'"}');
  163. }
  164. }
  165. $orderNoHead = substr($data['order_no'], 0, 2);
  166. $message = array_merge([
  167. 'out_trade_no' => $data['order_no'],
  168. 'transaction_id' => '',
  169. 'out_batch_no' => '',
  170. 'batch_status' => '',
  171. 'fail_count' => '',
  172. ], $data);
  173. }
  174. switch ($orderNoHead) {
  175. case 'UN':
  176. // 合并支付的订单
  177. $notify->UnionOrderNotify($message);
  178. break;
  179. case 'RG':
  180. // 充值订单
  181. $notify->RechargeOrderNotify($message);
  182. case OrderNo::INTEGRAL_RECHARGE:
  183. // 充值订单
  184. $notify->IntegralRechargeOrderNotify($message);
  185. break;
  186. case 'LV':
  187. // 会员购买
  188. $notify->LevelOrderNotify($message);
  189. break;
  190. case 'ML':
  191. // 商城订单
  192. $notify->MallOrderNotify($message);
  193. break;
  194. case 'SC':
  195. // 当面付订单
  196. $notify->ScanOrderNotify($message);
  197. break;
  198. case 'PC':
  199. // 联盟佣金提现订单
  200. $notify->saasProfitCash($message);
  201. break;
  202. case 'FO':
  203. // 点餐订单
  204. $notify->FoodNotify($message);
  205. break;
  206. case 'SG':
  207. // 店铺充值订单
  208. $notify->StoreReOrderNotify($message);
  209. break;
  210. case 'AM':
  211. //商盟会员卡订单
  212. $notify->BusinessMemberOrderNotify($message);
  213. break;
  214. case 'AL':
  215. //商盟会员购物订单
  216. $notify->BusinessNotify($message);
  217. break;
  218. case 'AD':
  219. // 认养费用
  220. $notify->AdoptCostOrderNotify($message);
  221. break;
  222. case 'AP':
  223. // 采购员订单
  224. $notify->APOrderNotify($message);
  225. break;
  226. case 'PR':
  227. \Yii::error([__METHOD__, 'PROrderNotify', $message]);
  228. // 采购员充值
  229. $notify->PROrderNotify($message);
  230. break;
  231. case 'LP':
  232. // 联盟券充值
  233. $notify->LPorderNotify($message);
  234. break;
  235. case 'PT':
  236. // 充值订单
  237. $notify->ptActivityOrderNotify($message);
  238. break;
  239. default:
  240. break;
  241. }
  242. return true; // 返回处理完成
  243. } catch (\Exception $e) {
  244. debug_log(['ADAPAY NOTIFY EXCEPTION <==========> ', $e->getMessage()], 'yunst.log');
  245. }
  246. }
  247. }