获取access_token,首先用一个方法 getAccess_token()封装起来,在此方法中写入代码:
首先,查找is_use字段为1的记录(说明这条记录可以获取到),获取到id号,判断此条记录的access_token是否存在,如果存在获取到微信的appid和appsecret,$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
function getAccess_token(){
$mp=M('mp')->where('is_use=1')->find();
if (empty($mp)) return false;
// exit;
$id=$mp['id'];
// dump($id);
if (empty($mp['access_token']) || $mp['expire_time']<time()) {
$appid=$mp['appid'];
// dump($appid);
$appsecret=$mp['appsecret'];
// dump($appsecret);
$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
// dump($url);
include_once APP_