关于微信开放平台获取token的问题,求大神帮忙

harry1688888 2018-01-13 09:38:34

appid 有传,一直报: {"errcode":41002,"errmsg":"appid missing hint: [HssC_0838e544]"}

请帮忙解决
...全文
1047 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeyuanzhi2016 2018-01-25
  • 打赏
  • 举报
回复
路过,学习了!!
hondely 2018-01-24
  • 打赏
  • 举报
回复
这个是获取access_token 以及获得当前二维码图片

<?php
/**
 * Created by PhpStorm.
 * User: 11536
 * Date: 2018/1/7
 * Time: 16:15
 */
class WeChat{
    private $_appid;
    private $_appsecret;
    private $_token;

    public function __construct($_appid,$_appsecret,$_token)
    {
        $this->_appid=$_appid;
        $this->_appsecret=$_appsecret;
        $this->_token=$_token;

    }

    public function _request($curl,$https=true,$method='GET',$data=null){
        $ch=curl_init();
        curl_setopt($ch,CURLOPT_URL,$curl);
        curl_setopt($ch,CURLOPT_HEADER,false);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        if($https){
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);
        }
        if($method=='POST'){
            curl_setopt($ch,CURLOPT_POST,true);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        }
        $content=curl_exec($ch);
        curl_close($ch);
        return $content;

    }
    public function _getAccessToken(){
        $file='./accesstoken';
        if(file_exists($file)){
            $content=file_get_contents($file);
            $content=json_decode($content);
            if(time()-filemtime($file)<$content->expires_in){
                return $content->access_token;
            }
        }
        $curl='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->_appid.'&secret='.$this->_appsecret;
        //echo $this->_request($curl);
        $content=$this->_request($curl);
        file_put_contents($file,$content);
        $content=json_decode($content);
        return $content->access_token;

    }
    public  function _getTicket($sceneid,$type='temp',$expire_seconds=604800){
        if($type=='temp'){
            $data='{"expire_seconds": %s, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": %s}}}';
            $data=sprintf($data,$expire_seconds,$sceneid);
        }else{
            $data='{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": %s}}}';
            $data=sprintf($data,$sceneid);
        }
        $curl='https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$this->_getAccessToken();
        $content=$this->_request($curl,true,'POST',$data);
        $content=json_decode($content);
        return $content->ticket;
    }
    public function _getQRcode($sceneid,$type='temp',$expire_seconds=604800){
        $ticket=$this->_getTicket($sceneid,$type,$expire_seconds);
        $ticket=urlencode($ticket);
        $content='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ticket;
        $qrcode=$this->_request($content);
        return $qrcode;
    }
}
$wechat=new WeChat('wx8e404573722b92f7','dea81a78de2d3f92f9fa965cd20cd9ec','');
//echo $wechat->_request('https://www.baidu.com');
//echo $wechat->_getAccessToken();
header('Content-type:image/jpeg');
echo $wechat->_getQRcode(30);
qq_27294663 2018-01-18
  • 打赏
  • 举报
回复
你要格式化成JSON 小程序以为 以为是字符串
harry1688888 2018-01-13
  • 打赏
  • 举报
回复
大神帮帮~~~

3,143

社区成员

发帖
与我相关
我的任务
社区描述
微信开发即微信公众平台开发,将企业信息、服务、活动等内容通过微信网页的方式进行表现,通过二次开发可以将公众账号由一个媒体型营销工具转化成提供服务的产品。
社区管理员
  • 微信开发
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧