Exemple #1
0
 public function index()
 {
     $this->weObj = getWeObj();
     $this->weObj->valid();
     $type = $this->weObj->getRev()->getRevType();
     $autoResponseDB = M('auto_response');
     if ($type == Wechat::MSGTYPE_TEXT) {
         $content = $this->weObj->getRevContent();
         $itemList = $autoResponseDB->where(array('key' => $content, 'status' => 1))->select();
         foreach ($itemList as $item) {
             $this->sendMSG($item);
         }
     } else {
         if ($type == Wechat::MSGTYPE_IMAGE) {
         } else {
             if ($type == Wechat::MSGTYPE_LOCATION) {
             } else {
                 if ($type == Wechat::MSGTYPE_LINK) {
                 } else {
                     if ($type == Wechat::MSGTYPE_EVENT) {
                         $event_type = $this->weObj->getRevEvent();
                         if ($event_type['event'] == Wechat::EVENT_SUBSCRIBE) {
                             $itemList = $autoResponseDB->where(array('status' => 1, 'msg_type' => 'event', 'sub_msg_type' => $event_type['event']))->select();
                             foreach ($itemList as $item_event) {
                                 $this->sendMSG($item_event);
                             }
                         }
                     } else {
                         if ($type == Wechat::MSGTYPE_MUSIC) {
                         } else {
                             if ($type == Wechat::MSGTYPE_NEWS) {
                             } else {
                                 if ($type == Wechat::MSGTYPE_VOICE) {
                                 } else {
                                     if ($type == Wechat::MSGTYPE_VIDEO) {
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     exit;
 }
Exemple #2
0
function getSubscribe($oauth2URL)
{
    //如果不是微信浏览器
    if (!isWeixinBrowser()) {
        //跳转到提示不是微信浏览器页面
        header("location:" . U("Error/errWXBrowser"));
        exit;
    }
    $weObj = getWeObj();
    $oauth2URL = 'http://' . $_SERVER['SERVER_NAME'] . $oauth2URL;
    //没有code就添加code
    if (empty($_REQUEST['code'])) {
        //跳转到关注页面
        header($weObj->getOauthRedirect($oauth2URL, "", "snsapi_base"));
        exit;
    } else {
        $code = $_REQUEST['code'];
        // print_r($code);
    }
    $openidArr = $weObj->getOauthAccessToken();
    p("{$openidArr}");
    $openid = $openidArr['openid'];
    if ($openid == "") {
        header($weObj->getOauthRedirect($oauth2URL, "", "snsapi_base"));
        exit;
    }
    $usrInfoArr = array();
    $usrInfoArr = $weObj->getUserInfo();
    if (!$usrInfoArr) {
        if ($weObj->errCode == "40001") {
            //$weObj->removeCache();
            $usrInfoArr = $weObj->getUserInfo();
        }
    }
    p($usrInfoArr);
    exit;
    if ($usrInfoArr['subscribe'] != "1") {
        //跳转到关注页面
        header("location:" . U("Error/WXfollow"));
        exit;
    }
    $userInfo['open_id'] = $openid;
    $userInfo['name'] = $usrInfoArr['nickname'];
    return $userInfo;
}