微網(wǎng)站制作教程圖解
第一步:首先,需要在微信公眾平臺上注冊一個自己的服務(wù)號或者訂閱號。

第二步:申請公眾賬號成功后,便可以使用其基本功能了,當(dāng)然,要想做成自己的微信官網(wǎng),則需要進入開發(fā)模式,接入第三方接口。



第三步:注冊成功并登陸第三方接口,將注冊好的微信公眾號添加到第三方接口上,所需信息在微信公眾號設(shè)置下的賬號信息里。

第四步:添加公眾賬號后,連接公眾平臺與第三方接口,如圖:登錄微信公眾平臺,點擊最左側(cè)最下方的【開發(fā)者中心】,點擊開發(fā)模式。

第五步:最后,設(shè)計自己的微信官網(wǎng)。并且可在線預(yù)覽。

完成以上步驟后,并且認(rèn)證訂閱號或服務(wù)號后就可以做微信的二次開發(fā)了,比如我要制作一個群發(fā)功能的接口,需要使用一下微信接口:
1、獲取access token
2、新增臨時素材接口
3、上傳圖文消息素材接口
4、調(diào)用群發(fā)接口
接口代碼示例: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數(shù)據(jù)提交
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;
}
//群發(fā)接口
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("文章標(biāo)題","文章內(nèi)容")->sendall();
建站流程
-
網(wǎng)站需求
-
網(wǎng)站策劃方案
-
頁面設(shè)計風(fēng)格
-
確認(rèn)交付使用
-
資料錄入優(yōu)化
-
程序設(shè)計開發(fā)
-
后續(xù)跟蹤服務(wù)
-
聯(lián)系電話
010-60259772
熱門標(biāo)簽
- 網(wǎng)站建設(shè)
- 食品網(wǎng)站建設(shè)
- 微信小程序開發(fā)
- 小程序開發(fā)
- 無錫網(wǎng)站建設(shè)
- 研究所網(wǎng)站建設(shè)
- 沈陽網(wǎng)站建設(shè)
- 廊坊網(wǎng)站建設(shè)
- 鄭州網(wǎng)站建設(shè)
- 婚紗攝影網(wǎng)站建設(shè)
- 手機端網(wǎng)站建設(shè)
- 高校網(wǎng)站制作
- 天津網(wǎng)站建設(shè)
- 教育網(wǎng)站建設(shè)
- 品牌網(wǎng)站建設(shè)
- 政府網(wǎng)站建設(shè)
- 北京網(wǎng)站建設(shè)
- 網(wǎng)站設(shè)計
- 網(wǎng)站制作
最新文章
推薦新聞
更多行業(yè)-
企業(yè)建站公司是做什么業(yè)務(wù)的,建設(shè)網(wǎng)站需要花很多錢嗎?
企業(yè)建站公司專門提供企業(yè)網(wǎng)站建設(shè)服務(wù),包括出具策劃案,設(shè)計網(wǎng)站主題,幫...
2023-03-21 -
網(wǎng)站制作技巧
專業(yè)個性化網(wǎng)站制作的技巧網(wǎng)站制作元素水平居中方法可以為這些需要居中的元...
2012-07-14 -
SEO網(wǎng)站優(yōu)化之百度快照排名優(yōu)化絕不能做的事情
SEO網(wǎng)站優(yōu)化之百度快照排名優(yōu)化絕不能做的事情大家都知道,要提高百度的...
2011-12-20 -
如何撰寫網(wǎng)絡(luò)市場調(diào)查報告
網(wǎng)絡(luò)市場調(diào)查報告的撰寫是網(wǎng)絡(luò)市場調(diào)查中的最后一個環(huán)節(jié)。撰寫市場調(diào)查報告...
2014-06-12 -
外貿(mào)網(wǎng)站建設(shè)中的一些細(xì)節(jié)問題
在外貿(mào)網(wǎng)站建設(shè)中有很多地方是需要大家注意的,本文只為大家列出幾個比較重...
2018-08-30 -
2015-11-24wordpress大改版,推出一款桌面應(yīng)用
尚品中國北京網(wǎng)站制作公司11月24日消息 據(jù)外媒消息稱,WordPre...
2015-11-24
預(yù)約專業(yè)咨詢顧問溝通!
免責(zé)聲明
非常感謝您訪問我們的網(wǎng)站。在您使用本網(wǎng)站之前,請您仔細(xì)閱讀本聲明的所有條款。
1、本站部分內(nèi)容來源自網(wǎng)絡(luò),涉及到的部分文章和圖片版權(quán)屬于原作者,本站轉(zhuǎn)載僅供大家學(xué)習(xí)和交流,切勿用于任何商業(yè)活動。
2、本站不承擔(dān)用戶因使用這些資源對自己和他人造成任何形式的損失或傷害。
3、本聲明未涉及的問題參見國家有關(guān)法律法規(guī),當(dāng)本聲明與國家法律法規(guī)沖突時,以國家法律法規(guī)為準(zhǔn)。
4、如果侵害了您的合法權(quán)益,請您及時與我們,我們會在第一時間刪除相關(guān)內(nèi)容!
聯(lián)系方式:010-60259772
電子郵件:394588593@qq.com