public function run()
 {
     require_once Yii::getPathOfAlias('ext') . "/OAuth/weixin/weixin.class.php";
     $wx = new WeiXin();
     $wx->getToken();
     var_dump($wx);
 }
Beispiel #2
0
 public function beforeAction()
 {
     //是否已经登录
     if (HSession::isLogin()) {
         $access_token_deadline = HSession::get('access_token_deadline', 0);
         if ($access_token_deadline > time()) {
             return parent::beforeAction();
         }
     }
     //获取code
     $code = $this->getParams('code', false);
     if ($code) {
         $user_data = WeiXin::model()->getUserWebAccessToken($code);
         $user_data['access_token_deadline'] = $user_data['expires_in'] + time();
         $user_info = WeiXin::model()->getSnsUserInfo($user_data['access_token'], $user_data['openid']);
         $user_data['nickname'] = isset($user_info['nickname']) ? $user_info['nickname'] : '';
         $user_data['sex'] = isset($user_info['sex']) ? $user_info['sex'] : '';
         $user_data['city'] = isset($user_info['city']) ? $user_info['city'] : '';
         $user_data['unionid'] = isset($user_info['unionid']) ? $user_info['unionid'] : '';
         HSession::login($user_data);
         return parent::beforeAction();
     }
     //跳转到微信auth2验证接口
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $auth2url = WeiXin::model()->getAuth2Url($url);
     $this->redirect($auth2url);
 }
 /**
  * @param      $token
  * @param null $appid
  * @param null $appsecret
  * @param bool $debug
  */
 public function __construct($token, $appid = null, $appsecret = null, $debug = false)
 {
     $this->token = $token;
     self::$debug = $debug;
     if (!empty($_GET) && $this->checkSignature()) {
         $this->handleRequest();
     }
     $this->appid = $appid;
     $this->appsecret = $appsecret;
 }
Beispiel #4
0
 public static function model()
 {
     if (self::$_model === null) {
         self::$_model = new WeiXin();
         $config_wx = H::app()->getConfig('weixin');
         self::$_model->_token = $config_wx['token'];
         self::$_model->_app_id = $config_wx['app_id'];
         self::$_model->_app_secret = $config_wx['app_secret'];
     }
     return self::$_model;
 }
Beispiel #5
0
 public function actionIndex()
 {
     $MsgType = WeiXin::model()->msg_type;
     if ($MsgType == 'text') {
         //文本消息
         WeiXin::model()->dealtext();
     } elseif ($MsgType == 'event') {
         //事件
         WeiXin::model()->dealevent();
     } else {
         echo '';
     }
 }
        $data = curl_exec($ch);
        //$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $data;
    }
}
?>

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    <?php 
$file = "C:/wamp4/www/token.txt";
$appid = "wx2c9e2b3c3e0cc058";
$appsecrect = "cf67d528c6aab80cebbfcd0ac20c8aee";
$noncestr = "dajiagame";
$wx = new WeiXin($appid, $appsecrect, $file, $noncestr);
$wx->initOpenInfo();
$wx->initApiInfo();
?>

    var sharesuccessfunc;
    var sharefuncobj;

    var obj = {};
    //邀请人
    obj.inviter = "<?php 
echo $wx->share;
?>
";
    //openId
    obj.id = "<?php 
Beispiel #7
0
 public static function getMsg()
 {
     $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
     //记录信息
     if (self::$_debug) {
         Log::write("weixin:" . $postStr, "ERR", 3, "weixin");
     }
     //解析xml
     if (!empty($postStr)) {
         self::$_msg = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
         self::$_msgtype = strtolower(self::$_msg['MsgType']);
     }
     return self::$_msg;
 }
Beispiel #8
0
<?php

require "config.php";
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$testFakeId = "{$argv['1']}";
$msg = `cat thinglist.txt`;
// echo '发送消息</br>';
// print_r($weiXin->send($testFakeId, "test"));
// echo '发送图片, 图片必须要先在公共平台中上传, 得到图片Id</br>';
// print_r($weiXin->sendImage($testFakeId, "10000001"));
// echo '批量发送</br>';
// print_r($weiXin->batSend(array($testFakeId, $testFakeId2), "test batSend"));
print_r($weiXin->send($testFakeId, "{$msg}"));
#echXin->send($testFakeId,"$msg"));
#"")o '得到最新消息,默认获取第一页消息</br>';
#$latestMsgs = $weiXin->getLatestMsgs();
#print_r($latestMsgs);
#if ($latestMsgs) {
#	echo $latestMsgs[0]['fakeid'],'</br>';
#	echo $latestMsgs[0]['date_time'],'</br>';
#	echo $latestMsgs[0]['content'],'</br>';
#}
#
#// 这个是可以得到的 只是 getLatestMsgs 这个抓取不太稳定,不能频繁去抓取
#// echo '得到用户Fakeid</br>';
#// $userFakeId = $weiXin->getLatestMsgByCreateTimeAndContent($createTime, $content);
#// print_r($userFakeId);
#
#// echo "开启高级模式</br>";
#// $openAdvancedSwitch = $weiXin->openAdvancedSwitch('1');
Beispiel #9
0
        curl_close($ch);
        return $data;
    }
}
?>


<script>

    <?php 
$file = "/keys/wx/token.txt";
$appid = "wxf04b146c252d167f";
$appsecrect = "fb53359cd830aafe60981cc690e2fb30";
$noncestr = "jyhd";
$redirectUri = "http://www.jyhdgame.cn/wx/rbkey/rbkey.php";
$wx = new WeiXin($appid, $appsecrect, $file, $noncestr, $redirectUri);
$wx->initOpenInfo();
?>

    var sharesuccessfunc;
    var sharefuncobj;

    var obj = {};
    //邀请人
    obj.inviter = "<?php 
echo $wx->share;
?>
";
    //openId
    obj.id = "<?php 
echo $wx->openid;
Beispiel #10
0
 public function index()
 {
     if (isset($_GET['echostr'])) {
         WeiXin::valid();
     } else {
         $msg = WeiXin::getMsg();
         $type = strtolower($msg['MsgType']);
         $username = $msg['FromUserName'];
         //哪个用户给你发的消息,这个$username是微信加密之后的,但是每个用户都是一一对应的
         switch ($type) {
             //文本
             case 'text':
                 if ($msg['Content'] == 'Hello2BizUser') {
                     //微信用户第一次关注你的账号的时候,你的公众账号就会受到一条内容为'Hello2BizUser'的消息
                     $reply = WeiXin::makeText('欢迎你关注奇艺果公众平台');
                 } else {
                     //这里就是用户输入了文本信息
                     $keyword = $msg['Content'];
                     //用户的文本消息内容
                     $arrayCon = array(array("Title" => "奇艺果网", "Description" => "买衣服,买抱枕,买手机壳到奇艺", "PicUrl" => "http://http://www.artqiyi.com/themes/default/images/logo.jpg", "Url" => "http://http://www.artqiyi.com/"));
                     $reply = WeiXin::makeNews($arrayCon);
                 }
                 break;
                 //链接
             //链接
             case 'link':
                 $reply = WeiXin::makeLink();
                 break;
                 //视频
             //视频
             case 'video':
                 $reply = WeiXin::makeVideo();
                 break;
                 //语音
             //语音
             case 'voice':
                 $reply = WeiXin::makeVoice();
                 break;
                 //图片
             //图片
             case 'image':
                 $reply = WeiXin::makeImage();
                 break;
                 //地理位置
             //地理位置
             case 'location':
                 //数据入库
                 $results['location_x'] = $msg['Location_X'];
                 $results['location_y'] = $msg['Location_Y'];
                 $results['openid'] = $msg['FromUserName'];
                 $results['createtime'] = $msg['CreateTime'];
                 WeixinUserLocation::addWeixinUserLocation($results);
                 //回复处理
                 WeiXin::makeLocation();
                 break;
             case 'event':
                 $reply = WeiXin::makeEvent($msg['Event']);
                 break;
             default:
                 # code...
                 break;
         }
         WeiXin::reply($reply);
     }
 }
Beispiel #11
0
<?php 
require "config.php";
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$lastMsg = $weiXin->getLatestMsgs();
//print_r($lastMsg);
$file = $lastMsg[0]['fakeid'] . '.jpg';
if (is_readable($file) == false) {
    $weiXin->getPicture($lastMsg[0]['fakeid']);
}
if ($lastMsg[0][type] == '1') {
    $messageid = $lastMsg[0]['id'];
    $fakeid = $lastMsg[0]['fakeid'];
    $nicheng = $lastMsg[0]['nick_name'];
    $content = $lastMsg[0]['content'];
    $nicheng = strip_tags($nicheng);
    $content = strip_tags($content);
    $content = @str_replace(array('"', '\'', '゛', '&nbsp;'), array('', '', '', ''), $content);
    $nicheng = @str_replace(array('"', '\'', '゛', '&nbsp;'), array('', '', '', ''), $nicheng);
    $imgurl = Web_ROOT . '/moni/' . $fakeid . '.jpg';
    $result = mysql_query("SELECT * FROM  `weixin_wall` WHERE  `fakeid` = '{$fakeid}'");
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    /* $sql = "INSERT INTO `weixin_wall` (`id`,`messageid`,`fakeid`,`num`,`content`,`nickname`,`avatar`,`ret`,`status`) VALUES (NULL,'$messageid','$fakeid ','-1','$content','$nicheng','$imgurl','0','0')";
    mysql_query($sql); */
    $sql_num = "SELECT * FROM  `weixin_wall_num` ";
    $query_num = mysql_query($sql_num);
    $q = mysql_fetch_row($query_num);
    $num = $q[0];
    $sql = "INSERT INTO `weixin_wall` (`id`,`messageid`,`fakeid`,`num`,`content`,`nickname`,`avatar`,`ret`,`status`) VALUES (NULL,'{$messageid}','{$fakeid} ','{$num}','{$content}','{$nicheng}','{$imgurl}','1','0')";
    mysql_query($sql);
    $sql_num = "UPDATE `weixin_wall_num` SET `num` = `num`+1";
Beispiel #12
0
<?php

require "config.php";
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$testFakeId = "160628835";
$testFakeId2 = "2158620204";
echo "<pre>";
// echo '发送消息</br>';
// print_r($weiXin->send($testFakeId, "test"));
// echo '发送图片, 图片必须要先在公共平台中上传, 得到图片Id</br>';
// print_r($weiXin->sendImage($testFakeId, "10000001"));
// echo '批量发送</br>';
// print_r($weiXin->batSend(array($testFakeId, $testFakeId2), "test batSend"));
echo '得到用户信息</br>';
print_r($weiXin->getUserInfo($testFakeId));
echo '得到最新消息,默认获取第一页消息</br>';
$latestMsgs = $weiXin->getLatestMsgs();
print_r($latestMsgs);
if ($latestMsgs) {
    echo $latestMsgs[0]['fakeid'], '</br>';
    echo $latestMsgs[0]['date_time'], '</br>';
    echo $latestMsgs[0]['content'], '</br>';
}
// 这个是可以得到的 只是 getLatestMsgs 这个抓取不太稳定,不能频繁去抓取
// echo '得到用户Fakeid</br>';
// $userFakeId = $weiXin->getLatestMsgByCreateTimeAndContent($createTime, $content);
// print_r($userFakeId);
// echo "开启高级模式</br>";
// $openAdvancedSwitch = $weiXin->openAdvancedSwitch('1');
// // print_r($openAdvancedSwitch);
Beispiel #13
0
 /**
  * 构造函数
  */
 function __construct()
 {
     $options = array('token' => WX_TOKEN, 'appid' => WX_APPID, 'appsecret' => WX_APPSECRET, 'log_callback' => 'debug_message', 'debug' => true);
     parent::__construct($options);
 }
Beispiel #14
0
<?php

$G_ROOT = dirname(__FILE__);
$G_CONFIG["weiXin"] = array('account' => 'ch-0431', 'password' => 'miao!@#$', 'cookiePath' => $G_ROOT . '/cache/cookie', 'webTokenPath' => $G_ROOT . '/cache/webToken');
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$lastMsg = $weiXin->getLatestMsgs();
print_r($lastMsg);
/* $file = $lastMsg[0]['fakeid'].'.jpg'; 
if (is_readable($file) == false) {
$weiXin->getPicture($lastMsg[0]['fakeid']);
}
if($lastMsg[0][type] == '1'){
$messageid = $lastMsg[0]['id'];
$fakeid = $lastMsg[0]['fakeid'];
$nicheng = $lastMsg[0]['nick_name'];
$content = $lastMsg[0]['content'];
$nicheng = strip_tags($nicheng);
$content = strip_tags($content);
$content = @str_replace(array('"','\'','゛','&nbsp;'), array('','','',''), $content);
$nicheng = @str_replace(array('"','\'','゛','&nbsp;'), array('','','',''), $nicheng);
$imgurl = Web_ROOT.'/moni/'.$fakeid.'.jpg';
} 
echo $nicheng; */