$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appSecret;
$result = $this->wxHttpsRequest($url);
//print_r($result);
$jsoninfo = json_decode($result, true);
$access_token = $jsoninfo["access_token"];
if ($access_token) {
$data->expire_time = time() + 7000;
$data->access_token = $access_token;
$fp = fopen("access_token.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
}
else {
$access_token = $data->access_token;
}
return $access_token;
}
/****************************************************
* 微信获取AccessToken 返回指定微信公众号的at信息
****************************************************/
public function wxJsApiTicket($appId = NULL , $appSecret = NULL){
$appId = is_null($appId) ? self::appId : $appId;
$appSecret = is_null($appSecret) ? self::appSecret : $appSecret;
$data = json_decode(file_get_contents("jsapi_ticket.json"));
if ($data->expire_time < time()) {
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=".$this->wxAccessToken();
$result = $this->wxHttpsRequest($url);
$jsoninfo = json_decode($result, true);
$ticket = $jsoninfo['ticket'];
if ($ticket) {
$data->expire_time = time() + 7000;
$data->jsapi_ticket = $ticket;
$fp = fopen("jsapi_ticket.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
}
else {
$ticket = $data->jsapi_ticket;
}
return $ticket;
}
/****************************************************
* 微信通过OPENID获取用户信息,返回数组
****************************************************/
public function wxGetUser($openId){
$wxAccessToken = $this->wxAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$wxAccessToken."&openid=".$openId."&lang=zh_CN";
$result = $this->wxHttpsRequest($url);
$jsoninfo = json_decode($result, true);
return $jsoninfo;
}
/****************************************************
* 微信生成二维码ticket
****************************************************/
public function wxQrCodeTicket($jsonData){
$wxAccessToken = $this->wxAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$wxAccessToken;
$result = $this->wxHttpsRequest($url,$jsonData);
return $result;
}
/****************************************************
* 微信通过ticket生成二维码
****************************************************/
public function wxQrCode($ticket){
$url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($ticket);
return $url;
}
/****************************************************
* 发送自定义的模板消息
****************************************************/
public function wxSetSend($touser, $template_id, $url, $data, $topcolor = '#7B68EE'){
$template = array(
'touser' => $touser,
'template_id' => $template_id,
'url' => $url,
'topcolor' => $topcolor,
'data' => $data
);
$jsonData = json_encode($template);
$result = $this->wxSendTemplate($jsonData);
return $result;
}
/****************************************************
* 微信设置OAUTH跳转URL,返回字符串信息 - SCOPE = snsapi_base //验证时不返回确认页面,只能获取OPENID
****************************************************/
public function wxOauthBase($redirectUrl,$state = "",$appId = NULL){
$appId = is_null($appId) ? self::appId : $appId;