示例#1
0
 public function getSgin($share_conf)
 {
     import('WechatApi');
     $tokenObj = new WechatApi(array('appid' => $this->appid, 'appsecret' => $this->appsecret));
     $access_token = $tokenObj->get_access_token();
     file_put_contents('token.txt', $access_token);
     $ticket = $this->getTicket($access_token['access_token']);
     $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $sign_data = $this->addSign($ticket, $url);
     $share_html = $this->createHtml($sign_data, $share_conf);
     return $share_html;
 }
示例#2
0
function isSub($openid)
{
    import('WechatApi');
    $tokenObj = new WechatApi(array('appid' => option('config.wechat_appid'), 'appsecret' => option('config.wechat_appsecret')));
    $access_token = $tokenObj->get_access_token();
    $url = 'https://api.weixin.qq.com/cgi-bin/user/info?openid=' . $openid . '&access_token=' . $access_token['access_token'];
    $classData = json_decode(Http::curlGet($url));
    if ($classData->subscribe == 0) {
        //没有关注
        return 0;
    } else {
        return 1;
    }
}
示例#3
0
 public function get_tmp_qrcode($qrcode_id)
 {
     $appid = option('config.wechat_appid');
     $appsecret = option('config.wechat_appsecret');
     if (empty($appid) || empty($appsecret)) {
         return array('error_code' => 1, 'msg' => '请联系管理员配置【AppId】【 AppSecret】');
     }
     import('Http');
     $http = new Http();
     //微信授权获得access_token
     import('WechatApi');
     $tokenObj = new WechatApi(array('appid' => $appid, 'appsecret' => $appsecret));
     $access_token = $tokenObj->get_access_token();
     $qrcode_url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token['access_token'];
     $post_data['expire_seconds'] = 604800;
     $post_data['action_name'] = 'QR_SCENE';
     $post_data['action_info']['scene']['scene_id'] = $qrcode_id;
     $json = $http->curlPost($qrcode_url, json_encode($post_data));
     if (!$json['errcode']) {
         return array('error_code' => 0, 'id' => $qrcode_id, 'ticket' => 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . urlencode($json['ticket']));
     } else {
         return array('error_code' => 1, 'msg' => '产生二维码发生错误。发生错误:错误代码 ' . $json['errcode'] . ',微信返回错误信息:' . $json['errmsg']);
     }
 }