Web Design
Mobile Internet
Brand Design
Innovative
News
Encyclopedias

Illustrations of micro website production tutorial

Date:2018-07-19 Source: Shangpin China Type: website encyclopedia
Word Size: small   medium   big

Shangpin China Website production Recently, the company found that many people were asking Microsite Today, I'm here to give you a unified answer to the questions of what is the micro website, what is its use, how to do it, and the construction process of the micro website. I hope it can help you who love learning.

Step 1: First, you need to register a service number or subscription number on the WeChat public platform.

 Illustration 1 of the course of making micro websites: Register your own service number or subscription number

Step 2: After successfully applying for a public account, you can use its basic functions. Of course, if you want to build your own WeChat official website, you need to enter the development mode and access the third-party interface.

 Illustration 2 of Micro Website Making Tutorial Micro website production diagram 3 WeChat official website

Step 3: Register successfully and log in to the third-party interface. Add the registered WeChat public account to the third-party interface. The required information is in the account information under the WeChat public account settings.

 Successful registration and login to the third-party interface

Step 4: After adding a public account, connect the public platform and the third-party interface, as shown in the figure: log in to the WeChat public platform, click the [Developer Center] at the bottom left, and click the development mode.

 Login to WeChat public platform

Step 5: Finally, design your own WeChat official website. And it can be previewed online.

 Design your own official WeChat website and preview it online


After completing the above steps and authenticating the subscription number or service number, we can do the secondary development of WeChat. For example, if I want to create an interface for mass sending, I need to use the following WeChat interface:

1. Get access token

2. Add temporary material interface

3. Upload image and text message material interface

4. Call mass sending interface

Example of interface code: WeixinApi.class.php

<? php
class WeixinApi{
private $appid,$appsecret,$media_id;
public function __construct($appid="",$appsecret=""){
$this->appid=$appid;
$this->appsecret=$appsecret;
}

//Get token
public function getToken(){
if($_COOKIE["exptime"]=="" || time()-$_COOKIE["create_time"]>=$_COOKIE["exptime"]){
$token=@file_get_contents(" //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 data submission
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;
}

//Upload media interface
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;
}

//Upload material
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;
}

//Mass sending interface
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;
}
}

use:
$weixin=new WeixinApi($appid,$appsecret);
$result=$weixin ->upload ("image", "image path") ->uploadnews ("article title", "article content") ->sendall();


Please contact our consultant

+86 10-60259772

Please provide your contact number. The project manager of shangpin China will contact you as soon as possible.