1. 程式人生 > >php微信公眾號模板訊息主動推送

php微信公眾號模板訊息主動推送

 public function get_token(){
            $m = new Common();
            $appid = $m->get_conf('UNION_WECHAT_MP_APPID');
            $appsec = $m->get_conf('UNION_WECHAT_MP_APPSEC');
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsec}";
            $raw = curl_get($url);
            if(strlen($raw)>0){
                $data = json_decode($raw,true);
                if(json_last_error()==JSON_ERROR_NONE){
                    if(key_exists('access_token',$data)){
                        return $data['access_token'];
                    }else{
                        return false;
                    }
                }else{
                    return false;
                }
            }else{
                return false;
            }
    }

2.獲取模板id,公眾號->新增功能外掛->模板訊息 裡申請。