1.在js接口安全域名中明设置你的业务域名
2.获取access_token以及jsticket
public function getvAssaceTokena(){
$appId = config('post_house.wx_appid');
$secret = config('post_house.wx_appsecret');
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$secret}";
return json_decode( https_request($url) )->access_token;
}
public function getvTicketa($token){
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$token."&type=jsapi";
return json_decode(https_request($url))->ticket;
}
3.生成随机数
public function createNonceStra($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
4.生成签名
public function sdksign($url){
$time =time();
if(Cache::get('post_token')){
$token = Cache::get('post_token');
}else{
$toke