'\app\plugins\scanCodePay\controllers\CallbackController::execute' ]; private $logIns; private $config; // public function __construct(){ // $this->logIns = Log::getInstance(); // $this->config = conf::getInstance(); // $this->config->loadConf(\Yii::$app->basePath.'/utils/yunst/src/Config/config.php'); //// dd($this->config); // // } // // public function actionTest() { // $order = Order::findOne(['order_no' => 'ML20230522140611637863']); // \app\utils\Adapay\Adapay::paymentConfirmQueryList($order);die; // $out_trade_no = input_params('out_trade_no'); // $data = [ // 'order_no' => $out_trade_no, // ]; // $this->notify($data, 317); // } // public function actionH5() { // $this->redirect(\Yii::$app->request->hostInfo . '/h5/static/h5/webview.html'); //// $this->redirect('http://192.168.0.159:8080/h5/static/h5/webview.html'); // } /** * 入口文件 * @throws \Exception */ public function actionIndex() { $store_id = get_params('store_id'); debug_log('yunst支付回调', 'yunst.log'); debug_log($store_id, 'yunst.log'); $post = all_params(); debug_log('来到yunst支付回调', 'yunst.log'); debug_log($post, 'yunst.log'); $this->logIns = Log::getInstance(); $this->config = conf::getInstance(); $this->config->loadConf(\Yii::$app->basePath.'/utils/yunst/src/Config/config.php'); $yunClient = new yunClient(); $res = $yunClient->checkPost($post); // $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"}'; // $post = json_decode($info,true); // echo '
';
//        print_r(json_decode($post['bizContent'],true));die();
        //验证签名成功
        if ($res){
            debug_log('验证签名成功', 'yunst.log');
            $bizContent = json_decode($post['bizContent'],true);
            debug_log($bizContent, 'yunst.log');
            if(isset($bizContent) && $bizContent['trxstatus'] == "0000"){
                $this->notify($bizContent, $store_id, 1);
                die;
            }

//            if(empty($post['data'])){
//                throw new \Exception('data参数为空');
//            }

        }




//        var_dump($post['data']);
//        $data = json_decode($post['data'], true);
//        if($data['status'] !== 'succeeded'){
//            return;
//        }
//        $orderNoHead = substr($data['order_no'], 0, 2);
//        $this->notify($data, $store_id);
    }

    /**
     * @param $data
     * @param $store_id
     * 回调逻辑处理
     */
    private function notify($data, $store_id, $isV2 = false) {
        \Yii::error(['YUNST NOTIFY INDEX  <==========> ', $store_id, $data]);

        try {

            $notify = new NotifyForm();

            if($isV2){
//                $data = [
//                    'store_id' => '84',
//                    'resp_desc' => '交易成功[000]',
//                    'resp_code' => '00000000',
//                    'sign' => 'p+Ys1lpCaEKhDON/+Bxj9fvLPAd/Xi54JmbQFs63yiT9jTM9SDV4TA5I6wssEGLT5WYdJFSj/yd5qz8b5SEIt6kw5bAeGpvcpY7YUb2Ffq/XY/1+HnXf+xESD9bUUgL7tNGom0d8MoLzsAEzS9lBiazJFuV7ueBQtKd2RpWSTiSt42JNQ2iMGvAsjGXc+oOfIqKu483LZVCuv/V7Ce5qkq8qEzQ1b/Vt1v01GYQugUdCvkqKagUnxq8/rTpjcOzUPWtGYVUeH3XBdeozZdv20TtJ/6dAnQBMVw6Ny1SfTLuZ5S+6gI4QINdkJSPXx7AmgcuTZPkszrGlN1lifEAcOA==',
//                    '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"}',
//                ];

                debug_log('走到支付回调', 'yunst.log');
                $notify = new NotifyForm();
                $orderNoHead = substr($data['outtrxid'], 0, 2);
                $notify->pay_type = Order::PAY_TYPE_YUNST_WECHAT_PAY;
                $notify->is_yunst = 1;
                $channelName = '微信';




//                $message = array_merge([
//                    'out_trade_no' => $data['outtrxid'],
//                    'transaction_id' => '',
//                    'out_batch_no' => '',
//                    'batch_status' => '',
//                    'fail_count' => '',
//                    'batch_status' => '',
//                    'batch_status' => '',
//                ], $data);
                if (isset($data['trxamt'])) {
                    $store = Store::findOne($store_id);
                    if ($store && !empty($store->device_name)) {
                        // $total_fee = $data['trxamt'];
                        $total_fee = round($data['trxamt'] / 100, 2);
                        $aaa = IotCloudHelper::sendMessage($store_id, '{"cmd":"voice","msg":"' . '微信收款'.$total_fee.'元","msgid":"'.$data['trxid'] .'"}');
                    }
                }

                $orderNoHead = substr($data['outtrxid'], 0, 2);
                $message = array_merge([
                    'out_trade_no' => $data['outtrxid'],
                    'transaction_id' => $data['trxid'],
                    'out_batch_no' => '',
                    'batch_status' => '',
                    'fail_count' => '',
                ], $data);

            }else{

                if(strstr($data['pay_channel'], 'wx_')){
                    $notify->pay_type = Order::PAY_TYPE_YUNST_WECHAT_PAY;
                    $channelName = '微信';
                }
                if(strstr($data['pay_channel'], 'alipay')){
                    $notify->pay_type = Order::PAY_TYPE_YUNST_ALI_PAY;
                    $channelName = '支付宝';
                }
                if (isset($data['pay_amt'])) {
                    $store = Store::findOne($store_id);
                    if ($store && !empty($store->device_name)) {
                        $total_fee = $data['pay_amt'];
                        IotCloudHelper::sendMessage($store_id, '{"cmd":"voice","msg":"' . $channelName . '收款'.$total_fee.'元","msgid":"'.$store_id. time() .'"}');
                    }
                }

                $orderNoHead = substr($data['order_no'], 0, 2);
                $message = array_merge([
                    'out_trade_no' => $data['order_no'],
                    'transaction_id' => '',
                    'out_batch_no' => '',
                    'batch_status' => '',
                    'fail_count' => '',
                ], $data);
            }

            switch ($orderNoHead) {
                case 'UN':
                    // 合并支付的订单
                    $notify->UnionOrderNotify($message);
                    break;
                case 'RG':
                    // 充值订单
                    $notify->RechargeOrderNotify($message);
                case OrderNo::INTEGRAL_RECHARGE:
                    // 充值订单
                    $notify->IntegralRechargeOrderNotify($message);
                    break;
                case 'LV':
                    // 会员购买
                    $notify->LevelOrderNotify($message);
                    break;
                case 'ML':
                    // 商城订单
                    $notify->MallOrderNotify($message);
                    break;
                case 'SC':
                    // 当面付订单
                    $notify->ScanOrderNotify($message);
                    break;
                case 'PC':
                    // 联盟佣金提现订单
                    $notify->saasProfitCash($message);
                    break;
                case 'FO':
                    // 点餐订单
                    $notify->FoodNotify($message);
                    break;
                case 'SG':
                    // 店铺充值订单
                    $notify->StoreReOrderNotify($message);
                    break;
                case 'AM':
                    //商盟会员卡订单
                    $notify->BusinessMemberOrderNotify($message);
                    break;
                case 'AL':
                    //商盟会员购物订单
                    $notify->BusinessNotify($message);
                    break;
                case 'AD':
                    // 认养费用
                    $notify->AdoptCostOrderNotify($message);
                    break;
                case 'AP':
                    // 采购员订单
                    $notify->APOrderNotify($message);
                    break;
                case 'PR':
                    \Yii::error([__METHOD__, 'PROrderNotify', $message]);
                    // 采购员充值
                    $notify->PROrderNotify($message);
                    break;
                case 'LP':
                    // 联盟券充值
                    $notify->LPorderNotify($message);
                    break;
                case 'PT':
                    // 充值订单
                    $notify->ptActivityOrderNotify($message);
                    break;
                default:
                    break;
            }
            return true; // 返回处理完成
        } catch (\Exception $e) {
            debug_log(['ADAPAY NOTIFY EXCEPTION  <==========> ', $e->getMessage()], 'yunst.log');
        }
    }
}