示例#1
0
 /**
  * 加密/校验流程:
  * 1. 将token、timestamp、nonce三个参数进行字典序排序 
  * 2. 将三个参数字符串拼接成一个字符串进行sha1加密 
  * 3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于易信 
  *
  * 若确认此次GET请求来自易信服务器,请原样返回echostr参数内容,则接入生效,否则接入失败。
  */
 public function join($params)
 {
     $signature = $params['signature'];
     $timestamp = $params['timestamp'];
     $nonce = $params['nonce'];
     $echostr = $params['echostr'];
     $mpa = TMS_APP::G('mp\\mpaccount');
     $p = array($mpa->token, $timestamp, $nonce);
     asort($p);
     $s = implode('', $p);
     $ss = sha1($s);
     if ($ss === $signature) {
         /**
          * 断开连接
          */
         TMS_APP::model()->update('xxt_mpaccount', array('yx_joined' => 'N'), "yx_appid='{$mpa->yx_appid}' and yx_appsecret='{$mpa->yx_appsecret}'");
         /**
          * 确认建立连接
          */
         TMS_APP::model()->update('xxt_mpaccount', array('yx_joined' => 'Y'), "mpid='{$this->mpid}'");
         return array(true, $echostr);
     } else {
         return array(false, 'failed');
     }
 }
示例#2
0
 /**
  * 加密/校验流程:
  * 1. 将token、timestamp、nonce三个参数进行字典序排序
  * 2. 将三个参数字符串拼接成一个字符串进行sha1加密
  * 3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于易信
  *
  * 若确认此次GET请求来自易信服务器,请原样返回echostr参数内容,则接入生效,否则接入失败。
  */
 public function join($data)
 {
     $signature = $data['signature'];
     $timestamp = $data['timestamp'];
     $nonce = $data['nonce'];
     $echostr = $data['echostr'];
     $mpa = TMS_APP::G('mp\\mpaccount');
     $tmpArr = array($mpa->token, $timestamp, $nonce);
     sort($tmpArr, SORT_STRING);
     $tmpStr = implode($tmpArr);
     $tmpStr = sha1($tmpStr);
     if ($tmpStr === $signature) {
         /**
          * 如果存在,断开公众号原有连接
          */
         TMS_APP::model()->update('xxt_mpaccount', array('wx_joined' => 'N'), "wx_appid='{$mpa->wx_appid}' and wx_appsecret='{$mpa->wx_appsecret}'");
         /**
          * 确认建立连接
          */
         TMS_APP::model()->update('xxt_mpaccount', array('wx_joined' => 'Y'), "mpid='{$this->mpid}'");
         return array(true, $echostr);
     } else {
         return array(false, 'failed.');
     }
 }
示例#3
0
 /**
  *
  */
 public function DecryptMsg($params, $data)
 {
     $mpa = TMS_APP::G('mp\\mpaccount');
     $msg_signature = $params['msg_signature'];
     $timestamp = $params['timestamp'];
     $nonce = $params['nonce'];
     $sMsg = "";
     $wxcpt = new WXBizMsgCrypt($mpa->token, $mpa->qy_encodingaeskey, $mpa->qy_corpid);
     $errCode = $wxcpt->DecryptMsg($msg_signature, $timestamp, $nonce, $data, $sMsg);
     if ($errCode != 0) {
         return array(false, $errCode);
     }
     return array(true, $sMsg);
 }
示例#4
0
 /**
  * 扫描二维码事件
  *
  * 企业号目前不支持场景二维码
  * 由于目前易信的场景二维码客户端无法收到回复信息,因此改为推动客户消息替代
  */
 private function qrcode_call($call)
 {
     $mpa = \TMS_APP::G('mp\\mpaccount');
     $mpid = $call['mpid'];
     $openid = $call['from_user'];
     $data = json_decode($call['data']);
     if ($reply = $this->model('reply')->qrcode_call($mpid, $data[1])) {
         if ($reply->expire_at > 0) {
             /**
              * 一次性二维码,用完后就删除
              */
             $this->model()->delete('xxt_call_qrcode', "id={$reply->id}");
         }
         if ($mpa->mpsrc === 'wx') {
             $r = $this->model('reply\\' . $reply->matter_type, $call, $reply->matter_id);
             $r->exec();
         } else {
             $setting = $this->model('mp\\mpaccount')->getSetting($mpid, 'yx_custom_push');
             if ($setting->yx_custom_push === 'N') {
                 return;
             }
             switch ($reply->matter_type) {
                 case 'enrollsignin':
                     // 登记活动签到
                     $r = $this->model('reply\\enrollsignin', $call, $reply->matter_id, false);
                     $r2 = $r->exec();
                     if ($r2['matter_type'] === 'enroll') {
                         $message = $this->model("matternroll")->forCustomPush($mpid, $r2['matter_id']);
                     } else {
                         if ($r2['matter_type'] === 'joinwall') {
                             $r = new $this->model('reply\\joinwall', $call, $r2['matter_id']);
                             $tip = $r->exec(false);
                             if (!empty($tip)) {
                                 $message = array("msgtype" => "text", "text" => array("content" => $tip));
                             }
                         } else {
                             $message = $this->model('matter\\' . $r2['matter_type'])->forCustomPush($mpid, $r2['matter_id']);
                         }
                     }
                     break;
                 case 'joinwall':
                     // 加入信息墙
                     $r = $this->model('reply\\joinwall', $call, $reply->matter_id);
                     $tip = $r->exec(false);
                     if (!empty($tip)) {
                         $message = array("msgtype" => "text", "text" => array("content" => $tip));
                     }
                     break;
                 default:
                     $message = $this->model('matter\\' . $reply->matter_type)->forCustomPush($mpid, $reply->matter_id);
             }
             /**
              * 发送消息
              */
             if (isset($message)) {
                 $rst = $this->sendByOpenid($mpid, $openid, $message);
                 if (false === $rst[0]) {
                     $err = is_array($rst[1]) ? implode(',', $rst[1]) : $rst[1];
                     $tr = $this->model('reply\\text', $call, $err, false);
                     $tr->exec();
                 }
             }
         }
     }
 }