:首先,需要需要微信平臺注冊個自己服務號訂閱號。。
第:申請賬號后,便后,便其基本功能,當然,當然,要,要想自己,則自己微信官網,則微信官網,則微信官網,接入
第三:注冊并第三方,將接口接口接口的微信公眾號到到第三方方,所上上上上上上
第四:添加,連接,連接連接第三方,如接口,如:登錄登錄:登錄微信,點擊平臺,點擊平臺,點擊最
第五:最后,設計設計微信官網。在線預覽。。
完成步驟,并且認證或服務號就可以的二次開發開發開發開發開發開發開發開發了了了了了了二二二二二二二二二二二二二二二二二二二二二次
1,訪問令牌
2,新增接口接口
3,傳消息素材接口接口
4,調用接口
接口:weixinapi.class.php
class WeixinApi{
private $appid,$appsecret,$media_id;
public function __construct($appid="",$appsecret=""){
$this->appid = $ appid;
$ this-> appsecret = $ appsecret;
}
//獲取令牌
公共功能getToken(){
if($ _ cookie [“ exptime”] ==“” || time() - $ _ cookie [“ create_time”]> = $ _ cookie [“ exptime”]){
$ token =@file_get_contents(“> appid}&secret = {$ this-> appsecret}”);
$ tokenarr = json_decode($ token,true);
setCookie(“ exptime”,$ tokenarr [“ expires_in”],0,'/');
setCookie(“ access_token”,$ tokenarr [“ access_token”],0,'/');
setCookie(“ create_time”,time(),0,'/');
}別的{
$ tokenarr = array(
“ access_token” => $ _ cookie [“ access_token”],
“ expires_in” => $ _ cookie [“ exptime”],
“ create_time” => $ _ cookie [“ create_time”]
);
}
返回$ tokenarr;
}
私有功能sockupload($ phost,$ pport,$ purl,$ filename,$ file_data = array()){
$ host = $ phost;
$ port = $ pport;
$ errno ='';
$ errstr ='';
$ timeout = 30;
$ url = $ purl;
$ file_data = array(
大批(
'name'=>'媒體',
'filename'=> $ filename,
//'path'=> '1.jpg'
)
);
//創建連接
$ fp = fsockopen($ host,$ port,$ errno,$ errdstr,$ timeout);
如果(!$ fp){
返回false;
}
// 發送請求
srand((double)microtime()*1000000);
$ boundare =“ ----------------------------------”。Substr(MD5(RAND(0,32000)),0,10);
$ data =“ - $ boundardrn”;
//形式數據
if(count($ form_data)> 0){
foreach($ form_data as $ key => $ val){
$ data。=“ content-disposition:form-data; name =“”。$ key。“ rn”;
$ data。=“ content-type:text/plainrnrn”;
$ data。= rawUrlencode($ val)。“ rn”;
$ data。=“ - $ boundardrn”;
}
}
//文件數據
if($ filename!=“”){
foreach($ file_data as $ file){
$ data。=“ content-disposition:form-data; name =“”。$ file ['name']。”; filename =“”。$ file ['fileName']。
$ pinfo = pathinfo($ file ['filename']);
$ data。=“ content-type:”。$ pinfo [“擴展”]。“ rnrn”;
$ data。= umpode(“”,file($ file ['fileName']))。“ rn”;
$ data。=“ - $ boundardrn”;
}
}
$ data。=“ - rnrn”;
$ out =“帖子 【大型網站公司】 $ {url} http/1.1rn“;
$ out。=“主機:$ {host} rn”;
$ out。=“ content-type:multipart/form-data; boundare = $ boundardrn”; // multipart/form-data
$ out。=“ content-Length:”。strlen($ data)。“ rn”;
$ out。=“連接:closernrn”;
$ out。=“ $ {data}”;
fputs($ fp,$ out);
//獲取響應
$ response ='';
while($ row = fread($ fp,4096)){
$ wendesp。= $ row;
}
$ pos = strpos($ wendesp,“ rnrn”);
$ revyse = substr($ wendesp,$ pos+4);
返回$響應;
}
// json數據提交
私有函數jsonupload($ url,$ jsdata){
$ data_string = $ jsdata;
$ ch = curl_init();
curl_setopt($ ch,curlopt_url,$ url);
curl_setopt($ ch,curlopt_post,1);
curl_setopt($ ch,curlopt_postfields,$ data_string);
curl_setopt($ ch,curlopt_returntransfer,1);
curl_setopt($ ch,curlopt_httpheader,數組(
'content-type:application/json; charset = utf-8',
“內容長度:”。 【企業網頁公司】 strlen($ data_string))
);
$結果= curl_exec($ ch);
curl_close($ ch);
返回$結果;
}
//上上接口
上傳公共功能($ type,$ filename){
$ 專業從事網頁開發 tokens = $ this-> getToken();
$ result = $ this-> sockupload(“ api.weixin.qq.com”,80,“/cgi-bin/media/upload?access_token =”。$ tokens [access_token“”]。 ”,$ filename);
$媒體= json_decode($ result,true);
$ this-> media_id = $媒體['Media_id'];
返回$ this;
}
//上傳素材
public函數uploadnews($ title,$ content,$ rution =“”,$ url =“”,$ digest =“”,$ show_cover_pic =“ 1”){
$ articles = array(陣列
“文章” =>陣列(
大批(
“ thumb_media_id” => $ this-> media_id,
“作者” => $作者,
“ title” => urlencode($ title),
“ content_source_url” => $ url,
“ content” => urlencode($ content),
“摘要” => $摘要,
“ show_cover_pic” =>“ 1”
)
)
);
$ tokens = $ this-> getToken();
$ news = uroldecode(json_encode($ 企業營銷型網站建設哪家好 atricles));
$ result = $ this-> jsonupload(“ api.weixin.qq.com/cgi-bin/media/uploadnews?access_token =”。$ tokens [“ access_token”]。
$ newsdata = json_decode($ result,true);
$ this-> media_id = $ newsdata [“ Media_id”];
返回$ this;
}
//群發接口
public函數sendall(){
$ arr = array(
“ filter” => array(“ is_to_all” => true,“ group_id” =>“”),
“ mpnews” => array(“ media_id” => $ this-> media_id),
“ msgtype” =>“ mpnews”
);
$ JSON = JSON_ENCODE($ arr);
$ tokens = $ this-> getToken();
$ result = $ this-> jsonupload(“ api.weixin.qq.com/cgi-bin/message/mass/mass/sendall?access_token =”。$ tokens [“ access_token”]。
返回$結果;
}
}
使用:
$ weixin = new weixinapi($ appid,$ appsecret);
$ result = $ weixin-> upload(“ image”,“”) - > uploadNews(“文章文章”,“文章”) - > sendall();
官網定制哪家好 那么上市公司網站建設哪家好?
請立即點擊咨詢我們或撥打咨詢熱線: 13968746378,我們會詳細為你一一解答你心中的疑難。項目經理在線