:首先,需要需要微信平台注册个自己服务号订阅号。。
第:申请账号后,便后,便其基本功能,当然,当然,要,要想自己,则自己微信官网,则微信官网,则微信官网,接入
第三:注册并第三方,将接口接口接口的微信公众号到到第三方方,所上上上上上上
第四:添加,连接,连接连接第三方,如接口,如:登录登录:登录微信,点击平台,点击平台,点击最
第五:最后,设计设计微信官网。在线预览。。
完成步骤,并且认证或服务号就可以的二次开发开发开发开发开发开发开发开发了了了了了了二二二二二二二二二二二二二二二二二二二二二次
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,我们会详细为你一一解答你心中的疑难。项目经理在线