public function actionPublish()
 {
     $accountId = $this->getAccountId();
     $redis = Yii::$app->cache->redis;
     $settings = $redis->get(self::SELF_SETTING_PREFIX . $accountId);
     $selfHelpDeskSetting = SelfHelpDeskSetting::findOne(['accountId' => new MongoId($accountId)]);
     if (!empty($settings)) {
         $settings = unserialize($settings);
         $settings['isPublished'] = true;
         $redis->set(self::SELF_SETTING_PREFIX . $accountId, serialize($settings));
         if (empty($selfHelpDeskSetting)) {
             $selfHelpDeskSetting = new SelfHelpDeskSetting();
         }
         $selfHelpDeskSetting['settings'] = $settings['settings'];
         $selfHelpDeskSetting['accountId'] = $settings['accountId'];
         if ($selfHelpDeskSetting->save()) {
             return ['status' => 'ok'];
         } else {
             return ['status' => 'failed'];
         }
     } else {
         if (!empty($selfHelpDeskSetting)) {
             $selfHelpDeskSetting->delete();
         }
         return ['status' => 'ok'];
     }
 }
 /**
  * Recieve message from weconnect
  *
  * <b>Request Type: </b>POST<br/>
  * <b>Content-Type: </b>application/json<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/chat/conversation/wechat-message<br/>
  * <b>Summary: </b>This api is for recieving a message from weconnect<br/>
  *
  * <b>Request Parameters: </b><br/>
  *     message: object, the content for the message<br/>
  *         message.msgType: string, "text"<br/>
  *         message.content: mixed, the body of the content<br/>
  *     account: object, the account information<br/>
  *     user: object, the user information<br/>
  *     userId: string, the wechat user id<br/>
  *
  * <b>Response Example</b>
  * <pre>{"status":"ok"}</pre>
  */
 public function actionWechatMessage()
 {
     $message = $this->getParams('message');
     $type = $message['msgType'];
     $content = $message['content'];
     $WEConnectAccountInfo = $this->getParams('account');
     $WEConnectUserInfo = $this->getParams('user');
     $accountId = $this->getAccountId();
     $args = ['message' => $message, 'account' => $WEConnectAccountInfo, 'user' => $WEConnectUserInfo, 'accountId' => (string) $accountId];
     $redis = \Yii::$app->cache->redis;
     $modeKey = SelfHelpDeskSetting::CONVERSATION_MODE_PREFIX . $accountId . '-' . $WEConnectUserInfo['id'];
     if (SelfHelpDeskSetting::exists($accountId)) {
         // use selfHelpDesk
         $selfHelpDeskFlag = $redis->get($modeKey);
         if (empty($selfHelpDeskFlag)) {
             $selfHelpDeskFlag = 'true';
         }
         switch ($selfHelpDeskFlag) {
             case 'false':
                 break;
             default:
                 SelfHelpDeskSetting::autoReply($args);
                 return ['status' => 'ok'];
                 break;
         }
     }
     $redis->set($modeKey, 'false', 'EX', SelfHelpDeskSetting::EXPIRED_TIME);
     Yii::$app->job->create('backend\\modules\\chat\\job\\WechatMessage', $args);
     return ['status' => 'ok'];
 }
Ejemplo n.º 3
0
 /**
  * Get the detail information of the self helpdesk setting
  *
  * <b>Request Type: </b>GET<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/helpdesk/setting/self-helpdesk<br/>
  * <b>Content-type: </b>Application/json<br/>
  * <b>Summary: </b>This api is for get the detail information of the self helpdesk setting.<br/>
  *
  * <b>Response Example: </b>
  * <pre>
  * {
  *     "id": "56187e882736e752058b4578",
  *     "settings": {
  *         "type": "reply",
  *         "content": "您好,很高兴为您服务,您可以输入序号查看一下内容:
  * [1] 卡片申请
  * [2] 办卡寄送进度查询
  * [3] 开卡/办卡
  * [4] 推荐亲友办卡",
  *         "menus": {
  *             "1": {
  *                 "content": "回复数字
  * 1. 绑定
  * 2. 解绑
  * 3. 返回上一级",
  *                 "type": "reply",
  *                 "menus": {
  *                     "1": {
  *                         "content": "您已绑定成功",
  *                         "type": "reply"
  *                     },
  *                     "2": {
  *                         "content": "已为您解绑",
  *                         "type": "reply"
  *                     },
  *                     "3": {
  *                         "content": "返回上一级",
  *                         "type": "back"
  *                     }
  *                 }
  *             },
  *             "2": {
  *                 "content": "回复数字
  * 1. 短信服务绑定
  * 2. 短信服务解绑
  * 3. 绑定手机重置密码
  * 4. 返回上一级",
  *                 "type": "reply",
  *                 "menus": {
  *                     "1": {
  *                         "content": "短信服务绑定成功",
  *                         "type": "reply"
  *                     },
  *                     "2": {
  *                         "content": "短信服务解绑成功",
  *                         "type": "reply"
  *                     },
  *                     "3": {
  *                         "content": "手机重置密码绑定成功",
  *                         "type": "reply"
  *                     },
  *                     "4": {
  *                         "content": "",
  *                         "type": "back"
  *                     }
  *                 }
  *             },
  *             "3": {
  *                 "content": "回复数字
  * 1. 密保绑定状态
  * 2. 密保卡使用状态
  * 3. 返回上一级",
  *                 "type": "reply",
  *                 "menus": {
  *                     "1": {
  *                         "content": "密保绑定成功",
  *                         "type": "reply"
  *                     },
  *                     "2": {
  *                         "content": "密保卡已被使用",
  *                         "type": "reply"
  *                     },
  *                     "3": {
  *                         "content": "",
  *                         "type": "back"
  *                     }
  *                 }
  *             },
  *             "4": {
  *                 "content": "",
  *                 "type": "connect",
  *                 "menus": [ ]
  *             }
  *         }
  *     }
  * }
  * </pre>
  */
 public function actionSelfHelpdesk()
 {
     $accountId = $this->getAccountId();
     if (!$accountId) {
         $accountId = $this->getQuery('cid');
     }
     if (empty($accountId)) {
         throw new BadRequestHttpException("AccountId is required");
     }
     return SelfHelpDeskSetting::findOne(['accountId' => $accountId]);
 }