您现在的位置是:宁波网站建设 > APP开发
微官网怎么制作,微网站设计图解,微站建设方法
宁波网站建设2024-09-20 16:24:03【APP开发】5人已围观
简介近发现特别多的人在问微网站是什么,微网站有什么用,微网站怎么做,微网站建设流程等问题,今天,在这里为大家统一解答,希望能对各位爱学习人士有所帮助。步:先,需要在微信公众平台上注册一个自己的服务号或者订
近发现特别多的微官网制网站微站人在问微网站是什么,微网站有什么用,作微微网站怎么做,设计微网站建设流程等问题,图解今天,建设在这里为大家统一解答,微官网制网站微站希望能对各位爱学习人士有所帮助。作微
步:先,设计需要在微信公众平台上注册一个自己的图解服务号或者订阅号。
第二步:申请公众账号成功后,便可以使用其基本功能了,微官网制网站微站当然,作微要想做成自己的设计微信官网,则需要进入开发模式,图解接入第三方接口。建设
第三步:注册成功并登陆第三方接口,将注册好的微信公众号添加到第三方接口上,所需信息在微信公众号设置下的账号信息里。
第四步:添加公众账号后,连接公众平台与第三方接口,如图:登录微信公众平台,点击左侧下方的【开发者中心】,点击开发模式。
第五步:后,设计自己的微信官网。并且可在线预览。
完成以上步骤后,并且认证订阅号或服务号后就可以做微信的二次开发了,比如我要制作一个群发功能的接口,需要使用一下微信接口:
1、获取access token
2、新增临时素材接口
3、上传图文消息素材接口
4、调用群发接口
接口代码示例:WeixinApi.class.php
<?php
class WeixinApi{
private $appid,$appsecret,$media_id;
public function __construct($appid="",$appsecret=""){
$this->appid=$appid;
$this->appsecret=$appsecret;
}
//获取token
public function getToken(){
if($_COOKIE["exptime"]=="" || time()-$_COOKIE["create_time"]>=$_COOKIE["exptime"]){
$token=@file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={ $this->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,'/');
}else{
$tokenarr=array(
"access_token"=>$_COOKIE["access_token"],
"expires_in"=>$_COOKIE["exptime"],
"create_time"=>$_COOKIE["create_time"]
);
}
return $tokenarr;
}
private function sockupload($phost,$pport,$purl,$filename,$file_data=array()){
$host = $phost;
$port = $pport;
$errno = '';
$errstr = '';
$timeout = 30;
$url = $purl;
/*$form_data = array(
'name' => 'lijie',
'gender' => 'man',
);*/
$file_data = array(
array(
'name' => 'media',
'filename' => $filename,
//'path' =>'1.jpg'
)
);
// create connect
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
if(!$fp){
return false;
}
// send request
srand((double)microtime()*1000000);
$boundary = "---------------------------".substr(md5(rand(0,32000)),0,10);
$data = "--$boundaryrn";
// form data
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 .= "--$boundaryrn";
}
}
// file data
if($filename!=""){
foreach($file_data as $file){
$data .= "Content-Disposition: form-data; name="".$file['name'].""; filename="".$file['filename'].""rn";
$pinfo=pathinfo($file['filename']);
$data .= "Content-Type: ".$pinfo["extension"]."rnrn";
$data .= implode("",file($file['filename']))."rn";
$data .= "--$boundaryrn";
}
}
$data .="--rnrn";
$out = "POST ${ url} HTTP/1.1rn";
$out .= "Host:${ host}rn";
$out .= "Content-type:multipart/form-data; boundary=$boundaryrn"; // multipart/form-data
$out .= "Content-length:".strlen($data)."rn";
$out .= "Connection:closernrn";
$out .= "${ data}";
fputs($fp, $out);
// get response
$response = '';
while($row=fread($fp, 4096)){
$response .= $row;
}
$pos = strpos($response, "rnrn");
$response = substr($response, $pos+4);
return $response;
}
//json数据提交
private function 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, array(
'Content-Type: application/json;charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close ( $ch );
return $result;
}
//上传媒体接口
public function upload($type,$filename){
$tokens=$this->getToken();
$result=$this->sockupload("api.weixin.qq.com",80,"/cgi-bin/media/upload?access_token=".$tokens["access_token"]."&type={ $type}",$filename);
$media=json_decode($result,true);
$this->media_id=$media['media_id'];
return $this;
}
//上传素材
public function uploadnews($title,$content,$author="",$url="",$digest="",$show_cover_pic="1"){
$articles=array(
"articles"=>array(
array(
"thumb_media_id"=>$this->media_id,
"author"=>$author,
"title"=>urlencode($title),
"content_source_url"=>$url,
"content"=>urlencode($content),
"digest"=>$digest,
"show_cover_pic"=>"1"
)
)
);
$tokens=$this->getToken();
$news=urldecode(json_encode($articles));
$result=$this->jsonUpload("api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=".$tokens["access_token"]."",$news);
$newsdata=json_decode($result,true);
$this->media_id=$newsdata["media_id"];
return $this;
}
//群发接口
public function 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/sendall?access_token=".$tokens["access_token"]."",$json);
return $result;
}
}
使用:
$weixin=new WeixinApi($appid,$appsecret);
$result=$weixin->upload("image","图片路径")->uploadnews("文章标题","文章内容")->sendall();
很赞哦!(8)
上一篇: 新站优化必须要做的优化项目有哪些?
下一篇: 在建设网站时应注哪些功能呢?
站长推荐
友情链接
- 长沙网站建设:探讨网站视觉设计的未来趋势
- 企业营销型网站如何进行运营管理?
- 长沙网站制作秘籍:营销效果实现低投入、高回报
- 长沙网站制作秘籍:营销效果实现低投入、高回报
- 长沙网站建设:探讨网站视觉设计的未来趋势
- 程序员们常用的开发工具都有哪些?
- 在长沙选择做网站,解析成功网站建设的关键因素
- 长沙网站设计中的意外惊喜:如何创造令人难忘的用户体验
- 长沙网站建设:网站开发所需时间的关键因素分析
- 互联网趋势下,企业网站的推广形式该如何抉择
- 极简风格深圳网站建设:关键技巧助你展现企业形象
- 95后喜欢什么样儿的互联网公司?
- 深圳网站建设流程:帮助企业打造线上品牌
- 长沙网站建设如何让用户情绪产生共鸣?
- 从长沙网站建设中,看如何建立高知名度的品牌
- 怎么理解品牌推广的定义?
- 怎样的网站才叫好网站?从多个角度来分析
- 了解这些小程序的技巧制作速度会更快呦
- 长沙网站设计中的意外惊喜:如何创造令人难忘的用户体验
- 提升市场竞争力:长沙企业网站建设的关键性角色