91精品91久久久中77777-亚洲免费观看视频-超碰成人免费-天天天操-欧美成人吸奶水做爰-国产精品三级视频-国产又大又黄又粗-福利视频网址导航-日本公公和儿媳-久久精品爱-日日操夜夜操天天操-亚洲精品日韩精品-91片黄-国产精品99久久久-丰满岳妇乱一区二区三区-美女主播福利视频-黄色高清在线观看-人妻在线一区二区-中文字幕激情视频-欧美日韩激情一区-色香视频首页-911成人网-天堂网在线看-亚洲怕怕-嫩草视频一区二区三区-成人在线不卡视频-国产重口老太伦-91嫩草在线播放-成人黄色动漫在线观看-韩国一级淫片免费看

首頁 > 新聞 > 知識賦能

微網站制作教程圖解

2017-07-19 9016
分享至:
尚品中國網站制作公司最近發現特別多的人在問微網站是什么,微網站有什么用,微網站怎么做,微網站建設流程等問題,今天,在這里為大家統一解答,希望能對各位愛學習人士有所幫助。

第一步:首先,需要在微信公眾平臺上注冊一個自己的服務號或者訂閱號。



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



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



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



第五步:最后,設計自己的微信官網。并且可在線預覽。




完成以上步驟后,并且認證訂閱號或服務號后就可以做微信的二次開發了,比如我要制作一個群發功能的接口,需要使用一下微信接口:

1、獲取access token

2、新增臨時素材接口

3、上傳圖文消息素材接口

4、調用群發接口

接口代碼示例:WeixinApi.class.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();
來源聲明:

本文章系尚品中國編輯原創或采編整理,如需轉載請注明來自尚品中國。以上內容部分(包含圖片、文字)來源于網絡,如有侵權,請及時與本站聯系(010-60259772)。

立即預約專屬顧問 開啟數字化轉型之旅!

10年+資深項目經理1V1服務 | 行業定制化方案 | 精準報價體系
獲取策劃方案
立即預約專屬顧問 開啟數字化轉型之旅!

咨詢我們,獲得專業的服務和報價

聯系我們,免費獲取項目方案及報價,或只是聊一聊您的項目? 在收到您的需求留言后我們將由專業人員于24小時內與您取得聯系,請您保持電話暢通!

  • 科研院所解決方案
  • 外貿出海解決方案
  • 協會學會解決方案
  • 集團上市公司解決方案
  • 生物醫藥解決方案
  • 制造業解決方案
  • 高校教育解決方案
  • 信創網站改造解決方案
更多服務咨詢,請聯系尚品

010-60259772

您的姓名 *
您的電話 *
您的郵箱
公司名稱 *