Esempio n. 1
1
 public static function scan($param)
 {
     list($data) = $param;
     self::_init();
     global $_G;
     if (!$_G['wechat']['setting']['wsq_allow']) {
         return;
     }
     $authcode = C::t('#wechat#mobile_wechat_authcode')->fetch_by_code($data['key']);
     if (!$authcode || $authcode['status']) {
         //			echo WeChatServer::getXml4Txt(lang('plugin/wechat', 'wechat_response_text_codeerror'));
     } else {
         if ($authcode['uid']) {
             $member = getuserbyuid($authcode['uid'], 1);
             if ($member['adminid'] == 0 && !$_G['wechat']['setting']['wechat_confirmtype']) {
                 C::t('#wechat#mobile_wechat_authcode')->update($authcode['sid'], array('uid' => $member['uid'], 'status' => 1));
                 $authcode['sid'] = '';
             }
         } else {
             $wechatuser = C::t('#wechat#common_member_wechat')->fetch_by_openid($data['from']);
             if ($wechatuser) {
                 $member = getuserbyuid($wechatuser['uid'], 1);
                 if ($member['adminid'] == 0 && !$_G['wechat']['setting']['wechat_confirmtype']) {
                     C::t('#wechat#mobile_wechat_authcode')->update($authcode['sid'], array('uid' => $member['uid'], 'status' => 1));
                     $authcode['sid'] = '';
                 }
             } elseif ($_G['wechat']['setting']['wechat_allowregister'] && $_G['wechat']['setting']['wechat_allowfastregister'] && $_G['wechat']['setting']['wechat_mtype'] == 2) {
                 require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.class.php';
                 require_once libfile('function/member');
                 $uid = WeChat::register(WeChat::getnewname($data['from']), 1);
                 if ($uid) {
                     WeChatHook::bindOpenId($uid, $data['from'], 1);
                     C::t('#wechat#mobile_wechat_authcode')->update($authcode['sid'], array('uid' => $uid, 'status' => 1));
                 }
                 wsq::report('register');
                 $authcode['sid'] = '';
             }
         }
         wsq::report('scanqr');
         self::_show('scan', $data['from'] . "\t" . $authcode['sid']);
     }
 }
Esempio n. 2
1
        wsq::report('bind');
        $url = wsq::wxuserregisterUrl($result['member']['uid']);
        showmessage('wechat:wechat_member_bind_succeed', $url);
    }
} elseif (($ac == 'register' && submitcheck('submit') || $ac == 'wxregister') && $_G['wechat']['setting']['wechat_allowregister']) {
    if ($wechatuser) {
        showmessage('wechat:wechat_openid_exists');
    } else {
        if ($ac == 'wxregister') {
            loaducenter();
            $user = uc_get_user($_GET['username']);
            if (!empty($user)) {
                $_GET['username'] = substr($_GET['username'], 0, 9) . '_' . random(5);
            }
        }
        $uid = WeChat::register($_GET['username']);
        if (!$_G['wechat']['setting']['wechat_qrtype']) {
            WeChatHook::bindOpenId($uid, $openid, 1);
            wsq::report('register');
            showmessage('wechat:wechat_member_register_succeed', $selfurl . 'bind&confirm=yes');
        } else {
            C::t('#wechat#common_member_wechatmp')->insert(array('uid' => $uid, 'openid' => $wxopenid ? $wxopenid : $_GET['wxopenid'], 'status' => 0), false, true);
            wsq::report('register');
            $url = wsq::wxuserregisterUrl($uid);
            if ($ac == 'wxregister') {
                dheader('location: ' . $url);
            } else {
                showmessage('wechat:wechat_member_register_succeed', $url);
            }
        }
    }
 public function validate()
 {
     // echo WECHAT_TOKEN;
     $wechat = new WeChat(WECHAT_TOKEN, true);
     //$wechat->checkSignature();
     $wechat->run();
 }
 public function getUserInfo($appIndex, $code)
 {
     $AppKey = Platform::$AppArr[$appIndex];
     $wechat = new WeChat($AppKey['AppID'], $AppKey['AppSecret']);
     $access_token = $this->getAccessToken($appIndex);
     $info = $wechat->getUserInfo($code, $access_token);
     return $info;
 }
Esempio n. 5
0
 public function AddLongSource($appIndex = 10)
 {
     $data = array('type' => 'image', 'media' => $_SERVER['DOCUMENT_ROOT'] . "/statics/images/2007119122519868_2.jpg");
     $assesstoken = D("WxAccessToken")->getAccessToken($appIndex);
     $AppKey = Platform::$AppArr[$appIndex];
     $wechat = new WeChat($AppKey['AppID'], $AppKey['AppSecret']);
     return $wechat->AddLongSource($assesstoken, $data);
 }
 /**
  * 获取ticket
  * @param unknown $appIndex
  * @return unknown
  */
 public function getJsApiTicket($appIndex = 10)
 {
     $whArr = array('mpid' => $appIndex);
     $rowArr = $this->where($whArr)->find();
     //参数 判别token是否有效,true-有效;false-无效;
     $TokenFlag = true;
     //对数据中的缓存token处理
     //数据库不存在accesstoken
     if ($this->where($whArr)->count() <= 0) {
         $TokenFlag = false;
     } else {
         $expiresDate = $rowArr['expired'] == null ? null : strtotime($rowArr['expired']);
         if ($expiresDate == null || $rowArr['jsapi_ticket'] == null) {
             $TokenFlag = false;
         } else {
             $nowtime = time();
             //与当前时间差是否超过2小时-分钟计算;
             $minteDif = $nowtime - $expiresDate;
             if ($minteDif >= 0) {
                 $TokenFlag = false;
             }
         }
     }
     if (!$TokenFlag) {
         //获取当前应用ID等信息
         $AppKey = Platform::$AppArr[$appIndex];
         $wechat = new WeChat($AppKey['AppID'], $AppKey['AppSecret']);
         $assesstoken = D('WxAccessToken')->getAccessToken($appIndex);
         $newRow = $wechat->getJsApiTicket($assesstoken);
         if ($newRow == null || $newRow['jsapi_ticket'] == null) {
             $newRow = $wechat->getJsApiTicket();
             if ($newRow == null || $newRow['jsapi_ticket'] == null) {
                 echo "获取不到jsapiticket";
                 exit;
             }
         }
         //保存数据库中
         $ok = $this->where($whArr)->delete();
         $newAdd['jsapi_ticket'] = $newRow['jsapi_ticket'];
         $newAdd['mpid'] = $appIndex;
         $newAdd['expired'] = date('Y-m-d H:i:s', $newRow['expire_time']);
         $this->add($newAdd);
         return $newAdd['jsapi_ticket'];
     } else {
         return $rowArr['jsapi_ticket'];
     }
 }
Esempio n. 7
0
 public static function run($config)
 {
     self::autoload();
     self::$token = new \WeChat\Token($config);
     self::$request = self::factory('Request');
     self::$response = self::factory('Response');
     self::$router = self::factory('Router');
 }
Esempio n. 8
0
 * 微信插件唯一入口文件.
 * @Created by Lane.
 * @Author: lane
 * @Mail lixuan868686@163.com
 * @Date: 14-1-10
 * @Time: 下午4:00
 * @Blog: Http://www.lanecn.com
 */
//引入配置文件
include_once __DIR__.'/config.php';
//引入自动载入函数
include_once __DIR__.'/autoloader.php';
//调用自动载入函数
AutoLoader::register();
//初始化微信类
$wechat = new WeChat(WECHAT_TOKEN, TRUE);

//首次使用需要注视掉下面这1行(26行),并打开最后一行(29行)
//echo $wechat->run();
//首次使用需要打开下面这一行(29行),并且注释掉上面1行(26行)。本行用来验证URL
//$wechat->checkSignature();


if(isset($_GET["signature"]) && isset($_GET["timestamp"]) && isset($_GET["nonce"]) && isset($_GET["echostr"])) {
    $wechat->checkSignature();
}
else {
    echo $wechat->run();
}

Esempio n. 9
0
$responseXML = '';
$time = time();
$responseArr = array();
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//get post data, May be due to the different environments
//extract post data
if (!empty($postStr)) {
    libxml_disable_entity_loader(true);
    $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
    try {
        $postArr = (array) $postObj;
        $content = isset($postArr['Content']) ? trim($postArr['Content']) : '';
        if (($mysql = initDataBase($schema)) == false) {
            throw new Exception($mysql->error);
        }
        $wechat = new WeChat($config);
        /* --------------------- log request ------------------------- */
        if ($postArr['MsgType'] == $wechat::MSGTYPE_EVENT && $postArr['Event'] == $wechat::EVENT_SEND_MASS) {
            $query = "UPDATE wechat_push_msg\n\t\t\tSET status = :status, totalCount = :totalCount,\n\t\t\tfilterCount = :filterCount, sentCount = :sentCount,\n\t\t\terrorCount = :errorCount, report_date = :report_date\n\t\t\tWHERE msg_id = :msg_id ";
            $bindArr = array('msg_id' => $postArr['MsgID'], 'status' => $postArr['Status'], 'totalCount' => $postArr['TotalCount'], 'filterCount' => $postArr['FilterCount'], 'sentCount' => $postArr['SentCount'], 'errorCount' => $postArr['ErrorCount'], 'report_date' => date('Y-m-d H:i:s'));
            if (!$mysql->execute($query, $bindArr)) {
                throw new Exception($mysql->error);
            }
            die(true);
        }
        getUserInfo($postArr['FromUserName']);
        $request_type = $postArr['MsgType'];
        switch ($postArr['MsgType']) {
            case $wechat::MSGTYPE_EVENT:
                $request_type = $postArr['Event'];
                if ($request_type == $wechat::EVENT_MENU_VIEW || $request_type == $wechat::EVENT_MENU_CLICK) {
Esempio n. 10
0
            setloginstatus($member, 1296000);
            dsetcookie('wechat_ticket', '', -1);
            $echostr = 'done';
        } else {
            $echostr = '1';
            //json_encode($authcode);
        }
    } else {
        $echostr = '-1';
    }
    if (!ob_start($_G['gzipcompress'] ? 'ob_gzhandler' : null)) {
        ob_start();
    }
    if ($echostr === 'done') {
        C::t('#wechat#mobile_wechat_authcode')->delete($authcode['sid']);
    }
    include template('common/header_ajax');
    echo $echostr;
    include template('common/footer_ajax');
    exit;
}
if ($_G['cookie']['qrauth']) {
    $qrauth = authcode(base64_decode($_G['cookie']['qrauth']), 'DECODE', $_G['config']['security']['authkey']);
}
if (!$_G['wechat']['setting']['wechat_qrtype']) {
    require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
    require_once DISCUZ_ROOT . './source/plugin/wechat/wsq.class.php';
    list($isqrapi, $qrcodeurl, $codeenc, $code) = WeChat::getqrcode();
    wsq::report('siteqrshow');
}
include_once template('wechat:wechat_qrcode');
Esempio n. 11
0
<?php

// 载入 WeChat 帮助类
require_once __DIR__ . '/wexin/ShsrainWeChat/WeChat/WeChat.php';
WeChat::run(array('grant_type' => 'client_credential', 'appid' => '', 'secret' => ''));
//echo WeChat::$response->news(WeChat::$request->getFromUserName(),'youpaiyunzhi',time(),1,array('title'=>'你好呀','description'=>'hellohellohello','url'=>'http://www.baidu.com'));
WeChat::$router->text('笑话', function () {
    echo WeChat::$response->text(WeChat::$request->getFromUserName(), 'youpaiyunzhi', time(), joke());
}, WeChat::$request);
WeChat::$router->text('hello', function () {
    echo WeChat::$response->news(WeChat::$request->getFromUserName(), 'youpaiyunzhi', time(), 1, array('title' => '你好呀', 'description' => 'hellohellohello', 'url' => 'http://www.baidu.com'));
}, WeChat::$request);
WeChat::$router->text('活动', function () {
    echo WeChat::$response->text(WeChat::$request->getFromUserName(), 'youpaiyunzhi', time(), '近期活动已经结束啦');
}, WeChat::$request);
WeChat::$router->text('抽奖', function () {
    echo WeChat::$response->text(WeChat::$request->getFromUserName(), 'youpaiyunzhi', time(), '抽奖活动已经结束啦');
}, WeChat::$request);
$contentStr = "欢迎关注优派健康。\n";
$contentStr .= "<a href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxca232ac09f1798ef&redirect_uri=http://api.didijiankang.cn/weixin/index.php/Home/Index/bindingAccountForm&response_type=code&scope=snsapi_base&state=123#wechat_redirect'>注册-绑定优派账号</a>。\n";
$contentStr .= "已绑定账号-<a href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxca232ac09f1798ef&redirect_uri=http://api.didijiankang.cn/weixin/index.php/Home/Index/displayMyConcern&response_type=code&scope=snsapi_base&state=123#wechat_redirect'>我的关注</a>。";
echo WeChat::$response->text(WeChat::$request->getFromUserName(), 'youpaiyunzhi', time(), $contentStr . " \n" . '回复:1:活动;2:抽奖;3:笑话');
function joke()
{
    $content = array('老夫妇去拍照,摄影师问:“大爷,您是要侧光,逆光,还是全光?",大爷腼腆的说:“我是无所谓,能不能给你大妈留条裤衩?"', '老婆语录:允许你喝醉,允许你勾妹,但晚上必须给老娘归队,如果你敢伤我的心,伤我的肺,老娘一定把你的第三条腿打残废,让你的鸟鸟永远打嗑睡。', '两个饺子结婚了,送走客人后新郎回到卧室,竟发现床上躺着一个肉丸子!新郎大惊,忙问新娘在哪?肉丸子害羞的说:讨厌,人家脱了衣服你就不认识啦!', '俩老夫妻某日吃晚饭时突发奇想:裸餐!找找从前的感觉!脱光后老太婆道:我还有反应耶!乳房还和年轻时一样发热!老头斜了一眼道:耷拉到汤里了!', '四只老鼠吹牛:甲:我每天都拿鼠药当糖吃;乙:我一天不踩老鼠夹脚发痒;丙:我每天不过几次大街不踏实;丁:时间不早了,回家抱猫去咯。 ', '天是蓝的,海是深的,男人的话没一句是真的;爱是永恒的,血是鲜红的,男人不打是不行的;男人如果是有钱的,和谁都是有缘的,男人靠的住,猪都会爬树。', '一群蚂蚁爬上了大象的背,但被摇了下来,只有一只蚂蚁死死地抱着大象的脖子不放,下面的蚂蚁大叫:掐死他,掐死他,小样,还他妈反了!', '小孩把妓院养的鹦鹉偷回家,一进门,鹦鹉便叫:搬家啦!看见他妈妈又叫:老板也换啦!看见他姐姐又叫:小姐也换了!看见他爸爸又叫:我cao还是老客!', '漫漫人生路,谁不错几步!家庭要照顾,情人也得处!家里有个做饭的,外面养个心善的,对桌坐个好看的,远方有个思念的!保住二,守住一,发展三四五六七!', '一只小狗爬上你的餐桌,向一只烧鸡爬去,你大怒道:你敢对那只烧鸡怎样,我就敢对你怎样,结果小狗舔了一下鸡屁股,你昏倒,小狗乐道:小样看谁狠。', '传说今晚,阴魂不散,死光又现,鬼魂四处转!愿鬼听到我的呼唤,半夜来到你庆头,苍白的脸,幽绿的眼,干枯的手抚摸你的脸,代我向你说一句:晚安!', '男人,总是笑容满面,两眼放电,不是发病犯贱,就是坑蒙拐骗!女人丰胸细腰,放荡风骚,不是掏你腰包,就是放你黑刀!这年月男怪女妖,小心中招啊!', '你走在路上,一母狗扑向你从你的脚上咬了一块肉,迅速吞下去,你伸脚正要踢它的时候,狗含着泪说:你打吧,反正我肚里已经有了你的骨肉!', '老鼠没女朋友特别郁闷,终于一只蝙蝠答应嫁给他,老鼠十分高兴。别人笑他没眼光,老鼠:你们懂什么,她好歹是个空姐。', '朋友问蝙蝠怎么会下嫁给老鼠,蝙蝠眼含泪花,意味深长:唉!那天他吃了伟哥,火力壮,一下蹦上天花板,让他得了手。', '我花一毛钱发这条短信给你,是为了告诉你——我并不是一个一毛不拔的人。比如这一毛钱的短信就是我送你的生日礼物。', '蚂蚁懒洋洋地躺在土里,伸出一只腿,朋友问你干嘛呢?蚂蚁:待会大象来了,绊他一跟头。', '喜鹊来,妈妈说这是喜鸟是客;燕子来,妈妈说这是益鸟是客;乌鸦来,孩子问你也是客人吗?乌鸦叫:Yes,吾乃黑客!', '某美女发现口红太重,拿湿纸巾擦拭后扔到路上。一老头拣起,端详半天突然醒悟,追上说:姑娘,这超薄的就是容易掉呀!', '黄瓜失恋痛哭,茄子安慰她:爱情不单只是甜美、只是沉醉,还有心碎、还有流泪。唉!谁让你爱上洋葱的? ', '昨天梦见上帝说可满足我一个愿望我拿出地球仪说要世界和平,他说太难换一个吧,我拿出你的照片说要这人变漂亮,他沉思了一下说拿地球仪我再看看。', '一女奇丑,嫁不出去,希望被拐卖。终于梦想成真,却半月卖不出去。绑匪将其送回,她坚决不下车,绑匪咬牙一跺脚:走,车不要了', '20年前爸爸抱着你等车,人都笑话孩子长得难看,爸爸哭了。一卖香蕉的老大爷拍拍爸爸说:“大兄弟别哭了,拿只香蕉给猴子吃吧!真可怜,饿的都没毛了。”', '飞机上,一只鹦鹉对空姐说:“给爷来杯水”,猪也学鹦鹉,对空姐说:“给爷来杯水”,空姐大怒,将鹦鹉和猪都扔下了飞机。这时鹦鹉对猪说:“傻B了吧,爷会飞。”', '好累了,不想讲了,看到你就像是一个笑话,呵呵哒。', '如何你看到我讲了几个重复的笑话,那是我在暗示,我累啦,不要让我讲笑话啦。');
    return $content[rand(0, 25)];
}
/**
 * wechat php test
 */
//define your token
Esempio n. 12
0
header('Content-type: text/json; charset=UTF-8');
require_once "../include/global.include.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $returnArr = array('code' => 200);
    if (!check_session()) {
        responseJSON('session expired', 440);
    }
    extract($_POST);
    if (!isset($appid) || !isset($app_secret)) {
        responseJSON('invalid request');
    }
    try {
        // validate app ID & app secret
        $_config = array('schema' => $_SESSION['schema'], 'appid' => $appid, 'secret' => $app_secret, 'encrypt_token' => null, 'encodingAESKey' => null, 'app_token' => null, 'app_token_expire' => null);
        // create a dummy class
        $_wechat = new WeChat($_config);
        // if id & secret are valid, access_token & expires_in will be returned
        // else errmsg & errcode will be obtained
        $result = $_wechat->validateSettings();
        if (isset($result['errcode'])) {
            $errmsg = $result['errmsg'];
            if ($result['errcode'] == 40001) {
                $errmsg = 'Invalid AppID or AppSecret.';
            } else {
                if ($result['errcode'] == 40125) {
                    $errmsg = 'Invalid AppSecret.';
                }
            }
            responseJSON($errmsg);
        }
        unset($_wechat);
Esempio n. 13
0
<?php

require_once dirname(__FILE__) . '/wxlib/wechat.class.php';
$obj = new WeChat();
/*
 * 首次配置使用 $obj->Token='c3a6f36fb5ec03eb'; $obj->valid();
 */
$obj->getData();
/*******************特殊事件处理部分开始********************/
//订阅事件
if ($obj->Event == 'subscribe') {
    require_once 'common/config.php';
    connect();
    $sql = "replace INTO `users`(`openid`,`mode`) VALUES ('{$obj->FromUserName}',0)";
    mysql_query($sql);
    $obj->replyText('感谢关注大交助手^^消息指令代号如下
    【1】今天课表
    【2】明天课表
    【3】成绩查询
    【4】天气查询
    【5】街景校园[荐]
    【6】考试安排
    【7】学习生活导航
    【8】常见问题
    【0】帮助菜单
    <a href="http://djzs.sinaapp.com/bdjw.php?openid=' . $obj->FromUserName . '">点击绑定教务在线使用全部功能</a>
    备:当前为新版测试中,请将您发现的bug和不足发送邮件至 admin@djtuhome.com,感谢您的使用^^
    ');
}
//帮助菜单
if ($obj->Content == '帮助' || $obj->Content == '0') {
Esempio n. 14
0
function switchFunc(WeChat $object, $keyword)
{
    $matches = explode("@", $keyword);
    $key = $matches[0];
    $value = $matches[1];
    switch ($key) {
        case "翻译":
            $content = wm_translate($value);
            $object->sendText($content);
            break;
        case "天气":
            $content = wm_weather($value);
            if (!is_array($content)) {
                $object->sendText($content);
            } else {
                foreach ($content as $v) {
                    $object->addNews($v['title'], "", "", $v['pic']);
                }
                $object->sendNews();
            }
            break;
        case "搜索":
            $articles = query("", $value);
            if (empty($articles)) {
                $object->sendText("没有找到相关文章");
            } else {
                foreach ($articles as $v) {
                    $object->addNews($v['0'], $v['1'], $v['2'], $v['3']);
                }
                $object->sendNews();
            }
            break;
        default:
            $object->addNews(WM_ERROR_MESSAGE, "", "", "");
            $object->addNews(WM_MESSAGE, "", "", "");
            $object->sendNews();
            break;
    }
}
Esempio n. 15
0
<?php

ini_set('display_errors', '1');
require './WeChat.class.php';
define('APPID', 'wxe647b92b9dc39f1b');
define('APPSECRET', 'e16374d53b5b78bf25fd7e29e3d58c46');
define('TOKEN', 'itcast_php34');
$wechat = new WeChat(APPID, APPSECRET, TOKEN);
$file = './Chrysanthemum.jpg';
$result = $wechat->uploadTmp($file, 'image');
var_export($result);
Esempio n. 16
0
extract($_GET);
if (isset($reg) && array_key_exists($reg, $SYSCONFIG['DB'])) {
    if (!isset($_SESSION['schema'])) {
        if (($mysql = initDataBase($SYSCONFIG['DB'][$reg])) == false) {
            throw new Exception($mysql->error);
        }
        # get app configs
        $query = "SELECT name, value FROM app_configs\n\t\tWHERE name IN( '%s' )";
        $_query = sprintf($query, implode('\', \'', $SYSCONFIG['APP_CONFIG']));
        $mysql->query($_query);
        $configs = array();
        foreach ($mysql->data as $config) {
            $configs[$config['name']] = $config['value'];
        }
        $config = array('schema' => $reg, 'appid' => $configs['appid'], 'secret' => $configs['app_secret'], 'encrypt_token' => $configs['encrypt_token'], 'encodingAESKey' => $configs['encodingAESKey'], 'app_token' => null, 'app_token_expire' => null);
        $wechat = new WeChat($config);
    }
    $header = 'Content-Type: image/png';
    $path = dirname(__DIR__) . '/global/images/not-found.png';
    if (isset($id)) {
        $query = "SELECT * FROM media_image WHERE id = ?";
        $bindArr = array($id);
        if (!$mysql->query($query, $bindArr)) {
            die($mysql->error);
        }
        if ($mysql->num_row > 0) {
            $media = $mysql->data[0];
            $path = '';
            if ($media['local_path'] != null) {
                $path = dirname(__DIR__) . $media['local_path'];
                $info = pathinfo($path);
Esempio n. 17
0
<?php

require_once '../common/set_inc.php';
if (!isset($_SESSION['openid'])) {
    //没有session,没有通过认证
    $weChat = new WeChat(APPID, APPSECRET, BASEPATH);
    if (isset($_GET['code'])) {
        //有code,已经完成跳转
        $openid = $weChat->Oauth_check($_GET['code']);
        if ($openid) {
            $res = $weChat->getUserInfo($openid);
            if ($res['subscribe'] == 1) {
                //已关注
                $_SESSION['openid'] = $openid;
                //记录用户信息
                $username = $res['nickname'];
                $patService->setDownUserName($openid, $username);
            } else {
                //未关注
                jump(ATTENTION_PAGE);
                exit;
            }
        }
    } else {
        //没有跳转,需要跳转去认证页面
        $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
        $weChat->Oauth_base($url);
        exit;
    }
}
if (isset($_SESSION['openid'])) {
Esempio n. 18
0
<?php

require './WeChat.class.php';
define('APPID', 'wxe647b92b9dc39f1b');
define('APPSECRET', 'e16374d53b5b78bf25fd7e29e3d58c46');
define('TOKEN', 'itcast_php34');
$wechat = new WeChat(APPID, APPSECRET, TOKEN);
$wechat->getQRCode(42, NULL);
Esempio n. 19
0
         }
     }
 }
 if (DISCUZ_VERSION < 'X3.0' && $_G['inajax']) {
     $_GET['username'] = WeChatEmoji::clear($_GET['username']);
 }
 if ($ac == 'wxregister') {
     loaducenter();
     $user = uc_get_user($_GET['username']);
     if (!empty($user)) {
         $_GET['username'] = cutstr($_GET['username'], 7, '') . '_' . random(5);
     }
 }
 $uid = WeChat::register($_GET['username'], $ac == 'wxregister');
 if ($uid && $_GET['avatar']) {
     WeChat::syncAvatar($uid, $_GET['avatar']);
 }
 if (!$_G['wechat']['setting']['wechat_qrtype']) {
     WeChatHook::bindOpenId($uid, $openid, 1);
     wsq::report('register');
     showmessage('wechat:wechat_member_register_succeed', $selfurl . 'bind&confirm=yes');
 } else {
     C::t('#wechat#common_member_wechatmp')->insert(array('uid' => $uid, 'openid' => $wxopenid ? $wxopenid : $_GET['wxopenid'], 'status' => 0), false, true);
     wsq::report('register');
     $url = wsq::wxuserregisterUrl($uid);
     if ($ac == 'wxregister') {
         dheader('location: ' . $url);
     } else {
         showmessage('wechat:wechat_member_register_succeed', $url);
     }
 }
Esempio n. 20
0
 function common()
 {
     global $_G;
     dsetcookie('mobile', '', -1);
     $redirect = WeChat::redirect(1);
     if ($redirect) {
         dheader('location: ' . $redirect);
     }
 }
Esempio n. 21
0
            C::t('#wechat#common_member_wechatmp')->insert(array('uid' => $_G['uid'], 'openid' => $_GET['openid'], 'status' => $_G['cookie']['qrauth'] ? 1 : 0), false, true);
        }
        dheader('location: ' . ($_GET['referer'] ? $_GET['referer'] : $_G['siteurl']));
    } else {
        require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.class.php';
        require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
        $defaultusername = WeChatEmoji::clear($_GET['nickname']);
        if (!$_G['wechat']['setting']['wechat_allowfastregister']) {
            redirectregister($defaultusername);
        }
        loaducenter();
        $user = uc_get_user($defaultusername);
        if (!empty($user)) {
            $defaultusername = cutstr($defaultusername, 7, '') . '_' . random(5);
        }
        $uid = WeChat::register($defaultusername, 1, 8);
        if (!$uid) {
            redirectregister($defaultusername);
        }
        C::t('#wechat#common_member_wechatmp')->insert(array('uid' => $uid, 'openid' => $_GET['openid'], 'status' => 0), false, true);
        $url = wsq::userregisterUrl($uid, $_GET['openid'], $_GET['openidsign'], $_GET['referer']);
        dheader('location: ' . $url);
    }
} elseif ($ac == 'regcallback' && $_G['uid']) {
    list($openid, $openidsign, $qrreferer) = explode("\t", authcode(base64_decode($_GET['auth']), 'DECODE'));
    if (!$openid) {
        showmessage('wechat:wechat_member_auth_fail');
    }
    C::t('#wechat#common_member_wechatmp')->insert(array('uid' => $_G['uid'], 'openid' => $openid, 'status' => 1), false, true);
    $url = wsq::userregisterUrl($_G['uid'], $openid, $openidsign, $qrreferer);
    dheader('location: ' . $url);
Esempio n. 22
0
<?php

require './WeChat.class.php';
define('APPID', 'wxe647b92b9dc39f1b');
define('APPSECRET', 'e16374d53b5b78bf25fd7e29e3d58c46');
define('TOKEN', 'itcast_php34');
$wechat = new WeChat(APPID, APPSECRET, TOKEN);
// $result = $wechat->menuDelete();
// var_dump($result);
//
$menu = <<<JSON
{
    "button": [
        {
            "name": "扫码",
            "sub_button": [
                {
                    "type": "scancode_waitmsg",
                    "name": "扫码带提示",
                    "key": "scancode_waitmsg",
                    "sub_button": [ ]
                },
                {
                    "type": "scancode_push",
                    "name": "扫码推事件",
                    "key": "scancode_push",
                    "sub_button": [ ]
                }
            ]
        },
        {
Esempio n. 23
0
<?php

/**
 * Created by PhpStorm.
 * User: hundredlee
 * Date: 1/7/16
 * Time: 9:01 AM
 */
error_reporting(0);
require 'WeChat.php';
define('MAX_GROUP_NUM', 35);
$weChat = new WeChat();
//设置uuid
$weChat->setUuid();
echo $weChat->getQRCode();
echo '<br/>';
sleep(2);
while (true) {
    if ($weChat->waitForLogin() == 200) {
        break;
    }
}
echo '<br/>';
if (!$weChat->login()) {
    echo '登录失败!<br/>';
    return;
} else {
    echo '登录成功!<br/>';
}
if (!$weChat->weChatInitial()) {
    echo '初始化失败!<br/>';
Esempio n. 24
0
 $query = "SELECT name, value FROM app_configs\n            WHERE name IN( '%s' )";
 $_query = sprintf($query, implode('\', \'', $SYSCONFIG['APP_CONFIG']));
 if (!$mysql->query($_query)) {
     throw new Exception($mysql->error);
 } else {
     if ($mysql->num_row == 0) {
         throw new Exception('App config not found');
     }
 }
 $configs = array();
 foreach ($mysql->data as $config) {
     $configs[$config['name']] = $config['value'];
 }
 $config = array('schema' => $schema, 'appid' => $configs['appid'], 'secret' => $configs['app_secret'], 'encrypt_token' => $configs['encrypt_token'], 'encodingAESKey' => $configs['encodingAESKey'], 'app_token' => null, 'app_token_expire' => null);
 # init Wechat API
 $wechat = new WeChat($config);
 // GET variables: timestamp, nonce, msg_signature, encrypt_type
 extract($_GET);
 if (isset($echostr)) {
     // for wechat API validation
     if ($wechat->validateAPI($echostr, $signature, $timestamp, $nonce)) {
         die($echostr);
     } else {
         throw new Exception('API validate failed');
     }
 }
 // get POST data, request message from WeChat
 $raw_data = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : '';
 if (!empty($raw_data)) {
     # decrypt message
     $dataArr = array('raw_data' => $raw_data, 'encrypt_type' => isset($encrypt_type) && $encrypt_type == 'aes' ? "aes" : "raw", 'msg_signature' => $msg_signature, 'timestamp' => $timestamp, 'nonce' => $nonce);
Esempio n. 25
0
<?php

namespace LaneWeChat;

use LaneWeChat\Core\Wechat;
/**
 * 微信插件唯一入口文件.
 * @Created by Lane.
 * @Author: lane
 * @Mail lixuan868686@163.com
 * @Date: 14-1-10
 * @Time: 下午4:00
 * @Blog: Http://www.lanecn.com
 */
//引入配置文件
include_once __DIR__ . '/config.php';
//引入自动载入函数
include_once __DIR__ . '/autoloader.php';
//调用自动载入函数
AutoLoader::register();
//初始化微信类
$wechat = new WeChat(WECHAT_TOKEN, TRUE);
//首次使用需要注视掉下面这1行(26行),并打开最后一行(29行)
echo $wechat->run();
//首次使用需要打开下面这一行(29行),并且注释掉上面1行(26行)。本行用来验证URL
//$wechat->checkSignature();
Esempio n. 26
0
<?php

header('Content-Type: text/html; charset=utf8');
require './WeChat.class.php';
define('APPID', 'wxe647b92b9dc39f1b');
define('APPSECRET', 'e16374d53b5b78bf25fd7e29e3d58c46');
define('TOKEN', 'itcast_php34');
$wechat = new WeChat(APPID, APPSECRET, TOKEN);
// 第一次验证:
// $wechat->firstValid();
//
// 处理威信公众平台的的消息(事件)
$wechat->responseMSG();
Esempio n. 27
0
 function common()
 {
     global $_G;
     if (!$_G['wechat']['setting']) {
         $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
     }
     dsetcookie('mobile', '', -1);
     if (!isset($_GET['pluginid'])) {
         $redirect = WeChat::redirect(1);
         if ($redirect) {
             dheader('location: ' . $redirect);
         }
     }
 }
Esempio n. 28
0
 public function createChatRoom($usernames = array())
 {
     $usernamesList = array();
     foreach ($usernames as $key => $value) {
         unset($usernames[$key]);
         $usernamesList[]['UserName'] = $value;
     }
     $url = sprintf(self::$base_uri . '/webwxcreatechatroom?pass_ticket=%s&r=%s', self::$pass_ticket, time());
     $params = array('BaseRequest' => self::$baseRequest, 'MemberCount' => count($usernamesList), 'MemberList' => $usernamesList, 'Topic' => '');
     $responseData = Requests::post($url, array('ContentType' => 'application/json; charset=UTF-8'), json_encode($params), array('cookies' => self::$cookie));
     $dictionary = json_decode($responseData->body, 1);
     self::$chatRoomName = $dictionary['ChatRoomName'];
     $memberList = $dictionary['MemberList'];
     foreach ($memberList as $key => $member) {
         if ($member['MemberStatus'] == 4) {
             self::$deleteList[] = $member['UserName'];
         }
     }
     if (strlen($dictionary['BaseResponse']['ErrMsg']) > 0) {
         echo $dictionary['BaseResponse']['ErrMsg'] . '<br/>';
     }
     return self::$chatRoomName;
 }