checkAuth() public method

通用auth验证方法
public checkAuth ( string $appid = '', string $appsecret = '', string $token = '' )
$appid string
$appsecret string
$token string 手动指定access_token,非必要情况不建议用
Exemplo n.º 1
0
function showTip($smarty, $tip, $db, $title)
{
    $options = array('token' => WX_TOKEN, 'appid' => WX_APPID, 'encodingaeskey' => '6pnP7qHyqJ1kFXMjuO4Z3QrpOa9WfapsgkPOtXoZKC2', 'appsecret' => WX_SECRET, 'logcallback' => logdebug);
    $we = new Wechat($options);
    $auth = $we->checkAuth();
    $js_ticket = $we->getJsTicket();
    $smarty->assign('tip', $tip);
    $smarty->assign('title', $title);
    $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $smarty->assign('js_sign', $we->getJsSign($url));
    $smarty->display('templates/tip.html');
    $db->disconnect();
    die;
}
Exemplo n.º 2
0
<?php

require_once '../config.php';
require_once '../db.php';
require_once '../wechat.class.php';
$options = array('token' => WX_TOKEN, 'appid' => WX_APPID, 'appsecret' => WX_SECRET, 'debug' => false, 'logcallback' => 'logdebug');
$weObj = new Wechat($options);
$weObj->checkAuth();
$ret = $weObj->getQRCode($_GET['id'], 1);
$url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($ret['ticket']);
echo "<img src='{$url}' /><a href='{$url}'>View in new page</a>";
Exemplo n.º 3
0
<?php

// WP_Wechat Handle
$wechat = new WP_Wechat();
// wechat-php-sdk Handle
$we = new Wechat(array('appsecret' => $wechat->app_secret, 'appid' => $wechat->app_id));
$auth = $we->checkAuth();
$js_ticket = $we->getJsTicket();
if (!$js_ticket) {
    $errcode = $we->errCode;
    $errtext = ErrCode::getErrText($weObj->errCode);
    echo "获取 js_ticket 失败! 错误码:{$errcode} 错误原因:{$errtext} ";
}
$https = isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'];
$url = ($https ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$js_sign = $we->getJsSign($url);
?>

<script>
    if(window.wx) {
        wx.config({
            debug: /debug=1/.test(location.href),
            appId: '<?php 
echo $js_sign['appId'];
?>
', // 必填,公众号的唯一标识
            timestamp: <?php 
echo $js_sign['timestamp'];
?>
, // 必填,生成签名的时间戳,切记时间戳是整数型,别加引号
            nonceStr: '<?php 
Exemplo n.º 4
0
 /**
  * 获取access_token的接口
  * @return [type] [description]
  */
 public function check_auth()
 {
     $appid = I('get.appid');
     $appsecret = I('get.appsecret');
     if (empty($appid) || empty($appsecret)) {
         echo json_encode(array('errmsg' => '信息不完整,请提供完整信息', 'errcode' => 1));
         exit;
     }
     $config = $this->model->table('wechat')->field('token, appid, appsecret')->where('appid = "' . $appid . '" and appsecret = "' . $appsecret . '" and status = 1')->find();
     if (empty($config)) {
         echo json_encode(array('errmsg' => '信息错误,请检查提供的信息', 'errcode' => 1));
         exit;
     }
     $obj = new Wechat($config);
     $access_token = $obj->checkAuth();
     if ($access_token) {
         echo json_encode(array('access_token' => $access_token, 'errcode' => 0));
         exit;
     } else {
         echo json_encode(array('errmsg' => $obj->errmsg, 'errcode' => $obj->errcode));
         exit;
     }
 }
Exemplo n.º 5
0
<?php

require_once '../config.php';
require_once '../function.php';
require_once '../db.php';
require_once '../wechat.class.php';
if ($_GET['p'][4] != ':') {
    $db = new DB();
    $db->connect();
    $weObj = new Wechat();
    $weObj->checkAuth(WX_APPID, WX_SECRET);
    echo "<img src='" . $weObj->getMediaURL($_GET['p']) . "'>";
    $db->disconnect();
} else {
    echo "<a href='" . $_GET['p'] . "'>" . $_GET['p'] . "</a><br>请复制链接查看原图,或打开链接后在地址栏回车重新打开。(刷新无用)";
}
Exemplo n.º 6
0
<?php

/**
 * Created by PhpStorm.
 * User: run
 * Date: 2015/7/15
 * Time: 11:36
 */
include "wechat.class.php";
$options = array('token' => 'vonvon', 'encodingaeskey' => 'encodingaeskey', 'appid' => 'wx519f23f4a45e8c37', 'appsecret' => 'ea8f0b17b3a0882bf5fda7ed27758482');
$weObj = new Wechat($options);
$weObj->valid();
//明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败
$openid = $weObj->getRev()->getRevFrom();
$token = $weObj->checkAuth();
$info = $weObj->getUserInfo($openid);
$type = $weObj->getRev()->getRevType();
switch ($type) {
    case Wechat::MSGTYPE_TEXT:
        $content = $weObj->getRev()->getRevContent();
        if (substr($content, 0, 6) == '姓名') {
            $name = substr($content, 6);
            $res = array("0" => array('Title' => $name . ', 你的生辰八字', 'Description' => 'Vonvon作为国际化的SNS社交媒体,从2015年1月起,在全世界已经拥有1亿以上的 用户。现在已在韩国,中国,台湾,泰国,越南,印尼,美国,巴西,西班牙等国家 开放。将来会拓展到更多的国家,并且会创作更多有趣的主题测试。', 'PicUrl' => 'http://cdn-cn-static-dr.vonvon.net/images/cn/recruit_main.jpg', 'Url' => 'http://cn.vonvon.net/'));
            $weObj->news($res)->reply();
        } else {
            $weObj->text("Your nickname is " . $info['nickname'] . "\nYour sex is " . $info['sex'] . "\nYour city is " . $info['city'] . "\nYour province is " . $info['province'] . "\n Your country is " . $info['country'] . "\nYour headimgurl is " . $info['headimgurl'] . "\nYour subscribe_time is " . date("Y-m-d H:i:s", $info['subscribe_time']) . "\nNow is " . date("Y-m-d H:i:s", time()))->reply();
            exit;
        }
        break;
    case Wechat::MSGTYPE_EVENT:
        $event = $weObj->getRev()->getRevEvent();