Introduction to WeChat Public platform development Tutorial (graphic), Public introductory tutorial _php tutorial

Source: Internet
Author: User

Introduction to Public Platform development tutorial (graphic), Public introductory tutorial


Key word: Getting Started with public platform development

Author: C + + Lab

Background: The development of public platform requires a certain basic knowledge of PHP, PHP is an embedded HTML language, widely used in web development. There are two ways to transfer data between the server and the developer's server, XML and JSON, respectively. Where XML is primarily used to accept sending ordinary messages and event pushes, while user management, creating custom menus and high-level mass, etc., need to use JOSN format data.

In this public platform development tutorial, you can follow the tutorial on the overall perceptual understanding of the development framework of the public platform, can help you better to start.

We will use the Public Account XI ' an campus maker space as an example of explanation, QR code see bottom.

This introductory tutorial will guide you through the following tasks:

Section I.

Apply for Sina cloud computing and create platform applications

section II apply for virtual hosting and build the environment for the platform

Here I use the cloud-connected virtual space for everyone to demonstrate, first of all, open the site such as:

then at the top right, follow the prompts to register and choose to use 1G free space.

2. Open the Control Panel after opening the space, you can see the host information.

3, Next we use 8uftp to login virtual space.

4. After logging in, use 8uftp to upload the index.php file to the Web folder in the root directory of the virtual space, as follows:

At this point, you use virtual space for the public platform to build a server is successful, follow-up as long as the implementation of the corresponding functions of the code through 8UFTP upload.

Section III Enabling Development mode and Access server

Public platform development model

Advanced Features

Public platform Address: https://mp.weixin.qq.com

Login to the public platform background, at the bottom of the list on the left, find "Basic Configuration", click to enter

Enter the server configuration fill box.

Click the "Modify Configuration" button to appear.

The URL here is the domain name of the cloud app described in the previous article, and token is defined as Weixin in index.php. Encodingaeskey do not fill, click on "Random generation" to automatically generate a, message and decryption mode Select "Clear text Mode", and then click the "Submit" button.

In the pop-up prompt box, click "OK"

After you configure the changes, click the Enable button

Ask "Are you sure you want to turn on server Configuration" and click "OK"?

If you are prompted to "token verification failed", you can do it several times, and the server is sometimes unstable. Note : If using Sina SAE may require real-name authentication, please upload ID card for real-name certification and pass the audit and then try again!

if it fails, test the URL and token correctly with the debugger first. (directly in Baidu search will have a lot of free OH)

fourth quarter invocation of interfaces and implementation of common functions

Example 1:api call Baidu Translator

Apply for Baidu Translator API interface

Here's how to use the Baidu translation API to create a public account with translation capabilities.

1, first, login application to become Baidu Developer, the application link address for http://developer.baidu.com/. After applying to become a developer, log in to the site and select Developer Services Management from the admin console drop-down menu, as shown in.

  1. We can translate the API by calling Baidu translate the English translation of Chinese, Chinese translation English, Chinese translation of Japanese, Japanese translation of Chinese. At present, Baidu AIP supports the translation of these three languages

  2. First enter the Baidu translation of the webpage, the website as shown below Arrow

  3. Click on "User Guide" after entering

  4. Access to the use of smart pages, the Web browsing page, in the middle part of the page, you can see Baidu translation API interface

  5. Based on the interface above, we can construct the interface code:

    http://openapi.baidu.com/public/2.0/bmt/translate?client_id=ua6zt1kh5o1uxvtruufjfhik&q={$keyword}&from =auto&to=auto

    "9penkh97n6b9ggj9zbke9tgq" This string for their own Baidu key, in the Application Center of Baidu Click Basic information can see

  6. The key code is:

    Case "Text";

    $tranurl = "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=ua6zt1kh5o1uxvtruufjfhik&q={$keyword }&from=auto&to=auto ";//Baidu translation address

    $transtr =file_get_contents ($tranurl);//Read into file

    $transon =json_decode ($TRANSTR);//json analysis

    Print_r ($transon);

    $contentStr = Read translated content $transon->trans_result[0]->dst;//

    Break

  7. Login to the phone, the result of the final implementation is as follows:

    The code used is as follows:
1 
 Php2 //6.2 Baidu Translation C + + laboratory CopyRight3 Define("TOKEN", "Weixin");4 $WECHATOBJ=Newwechatcallbackapitest ();5 if(!isset($_get[' Echostr '])) {6     $WECHATOBJ-responsemsg ();7}Else{8     $WECHATOBJ-valid ();9 }Ten  One classwechatcallbackapitest A { -      Public $fromUsername=''; -      Public $toUsername=''; the   Public functionvalid () -     { -         $echoStr=$_get["Echostr"]; -         if($this-checksignature ()) { +             Echo $echoStr; -             Exit; +         } A     } at  -     Private functionchecksignature () -     { -         $signature=$_get["Signature"]; -         $timestamp=$_get["Timestamp"]; -         $nonce=$_get["Nonce"]; in         $token=TOKEN; -         $TMPARR=Array($token,$timestamp,$nonce); to         Sort($TMPARR,sort_string); +         $tmpStr=implode($TMPARR); -         $tmpStr=SHA1($tmpStr); the  *         if($tmpStr==$signature){ $             return true;Panax Notoginseng}Else{ -             return false; the         } +     } A  the      Public functionresponsemsg () { +         $postStr=$GLOBALS["Http_raw_post_data"]; -             $POSTOBJ=simplexml_load_string($postStr, ' SimpleXMLElement ',libxml_nocdata); $                 $fromUsername=$POSTOBJ-Fromusername; $                 $toUsername=$POSTOBJ-Tousername; -                 $type=$POSTOBJ-Msgtype; -                 $event=$POSTOBJ-Event; the                 $Event _key=$POSTOBJ-Eventkey; -                 $mid=$POSTOBJ-MediaID;Wuyi                 $link=$POSTOBJ-Url; the              -                 $latitude=$POSTOBJ-location_x; Wu                 $longitude=$POSTOBJ-location_y; -                 $keyword=Trim($POSTOBJ-Content); About                 $time= Time(); $                  $TEXTTPL= "
 
    - 
   %s
 
                               
  - 
   %s
 
                               
  - 
   
    %s
                               
  A 
   text
 
                               
  + 
   %s
 
                               
  the                             ";  -                             if($keyword!=''){ $                             $id= "R90fxow4optcblkd9aiaihz0"; the $url= "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=$id&q=$keyword&from=auto&to=auto "; the $res=file_get_contents($url); the $res=json_decode ($res,true); the $contentStr=$res[' Trans_result '] [0] [' DST ']; -}$resultStr=sprintf($TEXTTPL,$fromUsername,$toUsername,$time,$contentStr); in                     Echo $resultStr; the   } the } About?>

Example 2:api called the small yellow Chicken

1. Register Simsimi Account

Url:http://developer.simsimi.com/signup

2. Activate account

3. Get API Key

4. Concrete Realization

Call the small yellow chicken API implementation

Call the Simsim ($keyword) function and replace the "Your API Key" with the API key you requested.

  //Small Yellow chicken C + + laboratory CopyRight     Public functionSimsim ($keyword){        $key= "41250A68-3CB5-43C8-9AA2-D7B3CAF519B1"; $url _simsimi= "http://sandbox.api.simsimi.com/request.p?key=".$key." &lc=ch&ft=0.0&text= ".$keyword; $json=file_get_contents($url _simsimi);//read the entire file into a string        $result=json_decode ($json,true);//encode the string in JSON format//$errorCode = $result [' result ']; For commissioning        $response=$result[' response '];//Reply to Message        if(!Empty($response)){            return $response; }Else{            $ran=Rand(1,5); Switch($ran){                 Case1:return"The small chicken is tired today, will accompany you to chat again tomorrow." ";  Break;  Case2:return"The chicken is sleeping.";  Break;  Case3:return"The Sound of the sound ~ ~";  Break;  Case4:return"You're talking a lot, not talking to you.";  Break;  Case5:return"Thank you for your interest in XI ' an campus creator space." \ n "." Number: Xaxymaker "." \ n ";  Break; default:return"Thank you for your interest in XI ' an campus creator space." \ n "." Number: Xaxymaker "." \ n ";  Break; }        }    }

At the same time, the public can also realize the Weather query train query Express query membership card, coupons, big turntable, micro-site, 3G album and so on. Micro-menu, micro-site, micro-member, micro-purchase, micro-research, micro-album, micro-Push, micro-statistics, micro-payment, micro-customer service, and so on.

The above is a simple public platform basic tutorial, if you have the intention to comprehend, feel you have something to gain, all started in practice, please follow the tutorial, start your development journey!! If there is nothing to understand, please sweep the public QR code attention, reply to "code", "Tutorial" ... All video tutorial code materials waiting for you!!!

Thank you for reading, please feel the heart! Hope can help the beginner of you!! Sharing is also a pleasure!!! Please relay ...

http://www.bkjia.com/PHPjc/1126417.html www.bkjia.com true http://www.bkjia.com/PHPjc/1126417.html techarticle Introduction to Public Platform development tutorial (graphic), Public introductory Tutorial keywords: Introduction to public platform development Author: C + + Lab background: development needs of public platform ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.