码迷,mamicode.com
首页 > 微信 > 详细

微信开发js config参数获得

时间:2015-08-20 12:44:57      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

//需要在这之前引入微信JS接口的引用文件
//http://res.wx.qq.com/open/js/jweixin-1.0.0.js
wx.config({
    appId: ‘‘, // 必填,公众号的唯一标识
    timestamp: , // 必填,生成签名的时间戳
    nonceStr: ‘‘, // 必填,生成签名的随机串
    signature: ‘‘,// 必填,签名,见附录1
    jsApiList: [ // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
      ‘openLocation‘,//这里不知道你用的地理接口是哪个就两个都写上了
      ‘getLocation‘
    ]
});
//签名的生成方法在附录1
//你需要access_token,这个用来获取jsapi_ticket。
//获取access_token需要用到appId和appsecrect。
//获取到后就是签名(sign).
//签名需要的参数有:jsapi_ticket,noncestr,timestamp及url(当前的url)
//采用字段名的ASCII码升序,使用URL键值对的格式(key=value&key=value)拼接
//如:jsapi_ticket=xxx&noncestr=xxx&timestamp=xxx&url=xxx
//最后对拼接出来的字符串用sha1签名,得到sign。放入config的参数里。
 
 

首先获取accesstoken,

$result = $this->http_get(‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=‘.$appid.‘&secret=‘.$appsecret);

$json = json_decode($result,true);

$this->access_token = $json[‘access_token‘];

 

private function http_get($url){
        $oCurl = curl_init();
        if(stripos($url,"https://")!==FALSE){
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
        $sContent = curl_exec($oCurl);
        $aStatus = curl_getinfo($oCurl);
        curl_close($oCurl);
        if(intval($aStatus["http_code"])==200){
            return $sContent;
        }else{
            return false;
        }
    }
 
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
            $res = json_decode ( $this->http_get ( $url ) );
            $ticket = $res->ticket;
 
private function getSignPackage($jsapiTicket,$url,$timestamp,$nonceStr) {
        // 这里参数的顺序要按照 key 值 ASCII 码升序排序
        $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
        $signature = sha1 ( $string );
 
        $signPackage["appId"] = C("APPID");
        $signPackage["nonceStr"] = $nonceStr;
        $signPackage["timestamp"] = $timestamp;
        $signPackage["url"] = $url;
        $signPackage["signature"] = $signature;
        $signPackage["rawString"] = $string;
        return $signPackage;
    }

微信开发js config参数获得

标签:

原文地址:http://www.cnblogs.com/Blogyy/p/4744689.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!