Beispiel #1
0
 /**
  *
  *获取微信所有用户
  * @account			微账号
  * @password		微密码
  * @datapath		cookie保存位置
  * @debug			错误是否开启 true false
  *
  */
 public function weiUserlist()
 {
     $systems = $this->systems();
     //$weiuser=M('weiuser');
     //模似登陆微信
     $options = array('account' => $systems['sys_weiAccount'], 'password' => $systems['sys_weiPassword'], 'datapath' => './temp/Data/cookie', 'debug' => true, 'logcallback' => 'logdebug');
     import("ORG.Weixin.Wechatext");
     $wechat = new Wechatext($options);
     // 获取所有用户		需添加分页跳转处理
     if ($wechat->checkValid()) {
         $userlist = reset($wechat->getUserlist());
         print_r($wechat->getInfo('2121015543'));
         exit;
         $weiuser->query('TRUNCATE ds_weiuser');
         //清空表
         foreach ($userlist as $id => $ut) {
             $array['fakeid'] = $ut['id'];
             $array['nick_name'] = $ut['nick_name'];
             $array['remark_name'] = $ut['remark_name'];
             $array['group_id'] = $ut['group_id'];
             $weiuser->add($array);
         }
         $this->success('更新成功', '__URL__/index');
     } else {
         echo "login error";
     }
 }
Beispiel #2
0
 public function respond()
 {
     $content = $this->message['content'];
     $from_user = $this->message['from'];
     //这里定义此模块进行消息处理时的具体过程, 请查看微擎文档来编写你的代码
     global $_W;
     $rid = $this->rule;
     $sql = "SELECT * FROM " . tablename('stubind_reply') . " WHERE `rid`=:rid LIMIT 1";
     $row = pdo_fetch($sql, array(':rid' => $rid));
     //自动获取用户信息
     $options = array('account' => $row['account'], 'password' => $row['password'], 'datapath' => $_W['attachurl'] . 'cookie_');
     $wechat = new Wechatext($options);
     if ($wechat->checkValid()) {
         $topmsg = $wechat->getTopMsg();
         $msgid = $topmsg['id'];
         //信息ID
         $fakeid = $topmsg['fakeid'];
         //fakeid
         $nick_name = $topmsg['nick_name'];
         //姓名
         $userdata = $wechat->getInfo($fakeid);
         $signature = $userdata['signature'];
         //备注
         $country = $userdata['country'];
         //国家
         $province = $userdata['province'];
         //省份
         $city = $userdata['city'];
         //城市
         $gender = $userdata['gender'];
         //性别 1男 2女
         $getHeadImg = $wechat->getHeadImg($fakeid);
         $HeadImgpath = 'stubind/headimg/' . $fakeid . '.jpg';
         $isfile_write = file_write($HeadImgpath, $getHeadImg);
         $sql = "SELECT * FROM " . tablename('stu_profile') . " WHERE `from_user`=:from_user LIMIT 1";
         $row_info = pdo_fetch($sql, array(':from_user' => $from_user));
         $insert = array('weid' => $_W['weid'], 'from_user' => $this->message['from'], 'fakeid' => $fakeid, 'wx_nickname' => $nick_name, 'signature' => $signature, 'country' => $country, 'province' => $province, 'city' => $city, 'avatar' => $HeadImgpath);
         if (!empty($insert)) {
             foreach ($insert as $field => $value) {
                 if (!isset($value)) {
                     unset($insert[$field]);
                     continue;
                 }
             }
         }
         if (empty($row_info['realname'])) {
             if (empty($row_info['id'])) {
                 $id = pdo_insert('stu_profile', $insert);
             }
             $sql = "SELECT * FROM " . tablename('stu_profile') . " WHERE `from_user`=:from_user LIMIT 1";
             $row_info = pdo_fetch($sql, array(':from_user' => $from_user));
             $response['FromUserName'] = $this->message['to'];
             $response['ToUserName'] = $this->message['from'];
             $response['MsgType'] = 'news';
             $response['ArticleCount'] = 1;
             $response['Articles'] = array();
             $response['Articles'][] = array('Title' => $row['title'], 'Description' => '戳进去进行【绑定】' . PHP_EOL . "微信名:" . $row_info['wx_nickname'] . PHP_EOL . $row_info['country'] . $row_info['province'] . $row_info['city'] . PHP_EOL . "签名:" . $row_info['signature'] . PHP_EOL . PHP_EOL . "如果上面微信信息与你的不符合,请重新回复【绑定】", 'PicUrl' => empty($row_info['avatar']) ? '' : $_W['attachurl'] . $row_info['avatar'], 'Url' => $_W['siteroot'] . $this->createMobileUrl('stubind', array('do' => 'stubind', 'name' => 'stubind', 'id' => $rid, 'from_user' => base64_encode(authcode($this->message['from'], 'ENCODE')))), 'TagName' => 'item');
         } else {
             pdo_update('stu_profile', $insert, array('from_user' => $from_user));
             $sql = "SELECT * FROM " . tablename('stu_profile') . " WHERE `from_user`=:from_user LIMIT 1";
             $row_info = pdo_fetch($sql, array(':from_user' => $from_user));
             $response['FromUserName'] = $this->message['to'];
             $response['ToUserName'] = $this->message['from'];
             $response['MsgType'] = 'news';
             $response['ArticleCount'] = 1;
             $response['Articles'] = array();
             $response['Articles'][] = array('Title' => $row['title'], 'Description' => '你【已经】绑定过了' . PHP_EOL . '戳进去【更新】或【解绑】' . PHP_EOL . PHP_EOL . "微信名:" . $row_info['wx_nickname'] . PHP_EOL . $row_info['country'] . $row_info['province'] . $row_info['city'] . PHP_EOL . "签名:" . $row_info['signature'] . PHP_EOL . PHP_EOL . "如果上面微信信息与你的不符合,请重新回复【绑定】", 'PicUrl' => empty($row_info['avatar']) ? '' : $_W['attachurl'] . $row_info['avatar'], 'Url' => $_W['siteroot'] . $this->createMobileUrl('stubind', array('do' => 'stubind', 'name' => 'stubind', 'id' => $rid, 'from_user' => base64_encode(authcode($this->message['from'], 'ENCODE')))), 'TagName' => 'item');
         }
     } else {
         $response['FromUserName'] = $this->message['to'];
         $response['ToUserName'] = $this->message['from'];
         $response['MsgType'] = 'news';
         $response['ArticleCount'] = 1;
         $response['Articles'] = array();
         $response['Articles'][] = array('Title' => $row['title'], 'Description' => $row['description'], 'PicUrl' => empty($row['thumb']) ? '' : $_W['attachurl'] . $row['thumb'], 'Url' => $_W['siteroot'] . $this->createMobileUrl('stubind', array('do' => 'stubind', 'name' => 'stubind', 'id' => $rid, 'from_user' => base64_encode(authcode($this->message['from'], 'ENCODE')))), 'TagName' => 'item');
     }
     return $response;
 }
Beispiel #3
0
<?php

/**
 * 微信扩展接口测试
 */
include "../wechatext.class.php";
function logdebug($text)
{
    file_put_contents('../data/log.txt', $text . "\n", FILE_APPEND);
}
$options = array('account' => '*****@*****.**', 'password' => 'demo', 'datapath' => '../data/cookie_', 'debug' => true, 'logcallback' => 'logdebug');
$wechat = new Wechatext($options);
if ($wechat->checkValid()) {
    // 获取用户信息
    $data = $wechat->getInfo('3974255');
    // 主动发消息
    //$wechat->send('3974255','hello '.time());
    var_dump($data);
}
Beispiel #4
0
function logdebug($text)
{
    file_put_contents('../data/log.txt', $text . "\n", FILE_APPEND);
}
$options = array('account' => '*****@*****.**', 'password' => 'demo', 'datapath' => '../data/cookie_', 'debug' => true, 'logcallback' => 'logdebug');
$wechat = new Wechatext($options);
if ($wechat->checkValid()) {
    //获取分组列表
    $grouplist = $wechat->getGroupList();
    var_dump($grouplist);
    //获取用户列表
    $userlist = $wechat->getUserlist(0, 10);
    var_dump($userlist);
    $user = $userlist[0];
    // 获取用户信息
    $userdata = $wechat->getInfo($user['id']);
    var_dump($userdata);
    // 获取已保存的图文消息
    $newslist = $wechat->getNewsList(0, 10);
    var_dump($newslist);
    //获取用户最新消息
    $topmsg = $wechat->getTopMsg();
    var_dump($topmsg);
    $msglist = $wechat->getMsg();
    var_dump($msglist);
    // 主动回复消息
    if ($topmsg && $topmsg['has_reply'] == 0) {
        $wechat->send($user['id'], 'hi ' . $topmsg['nick_name'] . ',rev:' . $topmsg['content']);
        $content = '这是一条Wechatext发出的测试微信';
        $imgdata = file_get_contents('http://github.global.ssl.fastly.net/images/modules/dashboard/bootcamp/octocat_fork.png');
        $img = '../data/send.png';