国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development Detailed example of WeChat development account based on IBM Bluemix

Detailed example of WeChat development account based on IBM Bluemix

Apr 27, 2017 pm 12:01 PM
ibm WeChat

Abstract: IBM has released Bluemix, and the number of WeChat public platform accounts has reached more than 2 million. If Bluemix can be used to develop WeChat public platform applications, this will be great news for the majority of WeChat developers. .

[Editor's Note] IBM recently released Bluemix, a platform-as-a-service (PaaS) environment based on open standards for building, running, and managing web and mobile applications in the cloud. The number of WeChat public platform accounts has reached more than 2 million. Therefore, if Bluemix can be used to develop WeChat public platform applications, the author believes that it will bring good news to the majority of WeChat developers to learn, deploy, test, and form commercial applications. Therefore, the author passed After research, we successfully completed the application development of WeChat public platform based on Bluemix. Here we will make some brief introduction to facilitate WeChat public developers to promote in-depth application.

Before developing the WeChat public platform, you need to apply for a WeChat public account. I will not go into details here. The name of the WeChat public account used by the author is: "Zhenghai Shuo Knowledge Innovation" and the code name is: "zhszscx". I will not go into details on how to apply for a WeChat public account.

Developing the WeChat public platform in Bluemix mainly includes the following steps:

Apply for a Bluemix account

Download and install the Cloud Foundry program

Compile the configuration of an application File

Set the development mode on the WeChat public platform

Set a Bluemix-based URL

Set the token of the WeChat public platform application

Download the sample program of the WeChat public platform. The author uses PHP language to modify the program and set the token (TOKEN)

Upload (push) the PHP file and the application starts executing

In WeChat In the public platform, verification is through edit mode.

Use WeChat on your mobile phone to send information to the WeChat public platform and obtain the information returned by the WeChat public platform.

At this point, the development of the WeChat public platform application based on Bluemix has been successfully completed, and developers can carry out further development on this basis.

Figure 1. System framework

Detailed example of WeChat development account based on IBM Bluemix

Process description

Apply for Bluemix account

Enter the URL: www.bluemix.net

Figure 2

Detailed example of WeChat development account based on IBM Bluemix

##Download and install the Cloud Foundry program

Figure 3

Detailed example of WeChat development account based on IBM Bluemix

Download the corresponding program according to the developer's program operating system.

Figure 4

Detailed example of WeChat development account based on IBM Bluemix

For example, the author's download address is: "Windows 64 bit" under Stable Installers

Downloaded a file, the The file is installer-windows-amd64 .zip

After installing this file, a cf.exe file is generated under C:\Program Files (x86)\Cloud Foundry. At the same time, after inspection, it was found that the directory has also been added to the PATH path of the system, which means that the CF command can be directly entered in the DOS COMMAND environment to execute the file.

Prepare an application configuration file

The file name is: manifest.yml As an application, you need to set the name of the application and the URL generated by the application. The example file is:

---applications:- name: cf-php-mysql1  memory: 256M  instances: 1  host: lzhfirstphp  domain: ng.bluemix.net  path: .  buildpack: <a href="https://github.com/dmikusa-pivotal/cf-php-build-pack.git">https://github.com/dmikusa-pivotal/cf-php-build-pack.git</a>

Description:

name specifies the name of the application

host specifies the extended domain name of the application. For example, the above example file generates the domain name:

lzhfirstphp.ng.bluemix .net

No other changes should be made. After the modification is completed, save the file.

There are three things to note when preparing this file:

The file format needs to be specified as UTF-8 format

When setting the application name, be careful not to repeat it.

When setting the HOST name, make it as long as possible, or set it according to the personal name or company name. The author once made an error when uploading the deployment. It is estimated that the name is duplicated. After later modification, the deployment was successful.

Set the development mode on the WeChat public platform

Enter the WeChat public platform, log in, enter the advanced functions, and set the development mode.

Figure 5

Detailed example of WeChat development account based on IBM Bluemix

Figure 6

Detailed example of WeChat development account based on IBM Bluemix##In the WeChat public platform interface, set the corresponding URL and token.

Figure 7

Detailed example of WeChat development account based on IBM BluemixSet a Bluemix-based URL

Set the URL in the URL. Note that the form here must be the same as the previous setting. consistent.

Set the token for the WeChat public platform application

Set a token information, which is specified by yourself, usually using special characters to ensure security .

下載微信公眾平臺(tái)的范例程序,筆者采用 PHP 語言,對(duì)該程序進(jìn)行修改,設(shè)置令牌(token)等相關(guān)信息。開發(fā)者可以在微信公眾平臺(tái)開發(fā)者文檔中下載 DEMO 文件。

圖 8

Detailed example of WeChat development account based on IBM Bluemix

清單 1

<?php/**  * wechat php test  *///define your tokendefine("TOKEN", "weixin");$wechatObj = new wechatCallbackapiTest();$wechatObj->valid();class wechatCallbackapiTest{public function valid()    {        $echoStr = $_GET["echostr"];        //valid signature , option        if($this->checkSignature()){        echo $echoStr;        exit;        }    }    public function responseMsg()    {//get post data, May be due to the different environments$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];      //extract post dataif (!empty($postStr)){                              $postObj = simplexml_load_string($postStr, &#39;SimpleXMLElement&#39;, LIBXML_NOCDATA);                $fromUsername = $postObj->FromUserName;                $toUsername = $postObj->ToUserName;                $keyword = trim($postObj->Content);                $time = time();                $textTpl = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content><FuncFlag>0</FuncFlag></xml>";             if(!empty( $keyword ))                {              $msgType = "text";                $contentStr = "Welcome to wechat world!";                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,                                          $msgType, $contentStr);                echo $resultStr;                }else{                echo "Input something...";                }        }else {        echo "";        exit;        }    }private function checkSignature(){        $signature = $_GET["signature"];        $timestamp = $_GET["timestamp"];        $nonce = $_GET["nonce"];        $token = TOKEN;$tmpArr = array($token, $timestamp, $nonce);sort($tmpArr, SORT_STRING);$tmpStr = implode( $tmpArr );$tmpStr = sha1( $tmpStr );if( $tmpStr == $signature ){return true;}else{return false;}}}?>

在這個(gè)文件中,有三處需要改動(dòng):

第一:設(shè)置 TOKEN

define("TOKEN", "abcdefg123");//第一處修改

這里的數(shù)值,需要與前面網(wǎng)頁中的 Token 的設(shè)置嚴(yán)格一致。

第二:這個(gè)范例程序中只是設(shè)置了驗(yàn)證模式,而沒有消息的響應(yīng)處理,筆者將該文件進(jìn)行了修改,當(dāng)存在驗(yàn)證參數(shù)時(shí)進(jìn)行驗(yàn)證,而不存在驗(yàn)證信息時(shí),則調(diào)用響應(yīng)方法。

if   ( $_GET["echostr"] )
 {
    $wechatObj->valid();
  }
  else
  {
   $wechatObj->responseMsg();
}

第三:在范例程序中,對(duì)輸入信息進(jìn)行了一點(diǎn)處理,設(shè)置為返回信息。

$contentStr = "Welcome to wechat world!".$keyword;

也就是將微信粉絲輸入的信息,加上"Welcome to wechat world!"后返回。

另外需要注意的是該 PHP 文件的編碼也必須是 UTF-8 的。上傳(push)PHP 文件,如果上傳正確,則等待應(yīng)用執(zhí)行。

該文件名指定必須與前述的配置文件完全一致。

在正常的配置結(jié)束后,就可以在 Bluemix 中看到該應(yīng)用,該應(yīng)用處于正常運(yùn)行的狀態(tài)。

圖 9

Detailed example of WeChat development account based on IBM Bluemix

cf api https://api.ng.bluemix.net
cf login

此處輸入申請(qǐng)的用戶郵件、密碼,執(zhí)行至運(yùn)行結(jié)束。

cf push -f manifest.yml

在微信公眾平臺(tái)中,點(diǎn)擊提交,系統(tǒng)會(huì)提示驗(yàn)證通過。如果提示驗(yàn)證不通過,需要檢查 URL、Token、程序中的 Token 以及程序代碼的正確性。

另外,需要注意的是,騰訊要求服務(wù)器響應(yīng)必須在 5 秒以內(nèi),因此在網(wǎng)絡(luò)環(huán)境不夠好的情況下,也許需要多提交幾次才可以完成。

特別需要注意的是,筆者曾經(jīng)進(jìn)行過新浪的微博開發(fā),新浪微博開發(fā)可以采取本地服務(wù)器,一樣可以驗(yàn)證通過,而騰訊的這種驗(yàn)證必須使用外部可以訪問的網(wǎng)址,筆者曾經(jīng)為此很困擾,而且騰訊的驗(yàn)證必須使用 80 端口,不支持 URL 帶端口號(hào),這也曾經(jīng)困擾過筆者。幸而 IBM 的 Bluemix 平臺(tái)可以支持。

利用手機(jī)微信,向微信公眾平臺(tái)發(fā)送信息,獲得微信公眾平臺(tái)返回的信息。

設(shè)置成功后,例如手機(jī)微信關(guān)注該微信公眾平臺(tái)賬號(hào),例如筆者的"正海說知識(shí)創(chuàng)新",賬號(hào):"zhszscx"關(guān)注的方法可以是名稱查詢、代號(hào)查詢,也可以掃描如下的二維碼,進(jìn)行體驗(yàn)。

想該賬號(hào)發(fā)送:hello!

將會(huì)收到系統(tǒng)返回的:Welcome to wechat world! hello!

這就表示基于 Bluemix 的微信公眾平臺(tái)開發(fā)順利完成。

開發(fā)中注意事項(xiàng)

對(duì)于前面開發(fā)中介紹到的可能出現(xiàn)問題的地方再做一些總結(jié):

正確設(shè)置 HOST 名稱,不可以重復(fù)。

HOST 名稱加上域名,需要和微信公眾平臺(tái)中的 URL 相匹配。

程序中的 Token 的設(shè)置必須同微信公眾平臺(tái)中的設(shè)置相匹配。

配置文件必須使用 UTF-8 格式。

Index.php 程序文件格式必須使用 UTF-8 格式。

系統(tǒng)未做說明,但是默認(rèn)采用的是 index.php 文件作為入口,也就是說,如果按本文所敘述的程序編制方法,利用域名訪問時(shí),將沒有結(jié)果展示。

在微信公眾平臺(tái)提交時(shí),可能顯示失敗,需要提交多次,知道顯示成功。

另外需要說明的是,目前的程序只對(duì)文本型微信信息進(jìn)行了回復(fù),其他信息未做處理。而開發(fā)者如果在開發(fā)中需要變更程序,則需要再次 PUSH 就可以,但是不需要在微信編輯模式再次提交。

發(fā)展展望

筆者在前述的基礎(chǔ)上,又增加了數(shù)據(jù)庫的鏈接,主要是 MYSQL 服務(wù)的建立、MYSQL 服務(wù)與應(yīng)用的綁定,在 PHP 程序文件中實(shí)現(xiàn)服務(wù)的參數(shù)調(diào)用,數(shù)據(jù)表的創(chuàng)建、插入、顯示,成功實(shí)現(xiàn)了數(shù)據(jù)庫的處理,另外也成功部署了基于 PHP 的網(wǎng)站形式的應(yīng)用,有了這樣的基礎(chǔ),說明可以利用 IBM 的 Bluemix 平臺(tái)實(shí)現(xiàn)開發(fā)微信公共賬號(hào)應(yīng)用。

The above is the detailed content of Detailed example of WeChat development account based on IBM Bluemix. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
TikTok web version entrance login link address https TikTok web version entrance website free TikTok web version entrance login link address https TikTok web version entrance website free May 22, 2025 pm 04:24 PM

The login portal for the Douyin web version is https://www.douyin.com/. The login steps include: 1. Open the browser; 2. Enter the URL https://www.douyin.com/; 3. Click the "Login" button and select the login method; 4. Enter the account password; 5. Complete login. The web version provides functions such as browsing, searching, interaction, uploading videos and personal homepage management, and has advantages such as large-screen experience, multi-tasking, convenient account management and data statistics.

Copy comics (official website entrance)_Copy comics (nba) genuine online reading portal Copy comics (official website entrance)_Copy comics (nba) genuine online reading portal Jun 05, 2025 pm 04:12 PM

Copying comics is undoubtedly a treasure that cannot be missed. Here you can find basketball comics in various styles, from passionate and inspiring competitive stories to relaxed and humorous daily comedy. Whether you want to relive the classics or discover new works, copying comics can meet your needs. Through the authentic online reading portal provided by copy comics, you will bid farewell to the trouble of pirated resources, enjoy a high-definition and smooth reading experience, and can support your favorite comic authors and contribute to the development of authentic comics.

Which is better, uc browser or qq browser? In-depth comparison and evaluation of uc and qq browsers Which is better, uc browser or qq browser? In-depth comparison and evaluation of uc and qq browsers May 22, 2025 pm 08:33 PM

Choosing UC browser or QQ browser depends on your needs: 1. UC browser is suitable for users who pursue fast loading and rich entertainment functions; 2. QQ browser is suitable for users who need stability and seamless connection with Tencent products.

Top 10 AI writing software rankings Recommended Which AI writing software is free Top 10 AI writing software rankings Recommended Which AI writing software is free Jun 04, 2025 pm 03:27 PM

Combining the latest industry trends and multi-dimensional evaluation data in 2025, the following are the top ten comprehensive AI writing software recommendations, covering mainstream scenarios such as general creation, academic research, and commercial marketing, while taking into account Chinese optimization and localization services:

Watch the official page of NIS comics online for free comics. The free entry website of NIS comics login page Watch the official page of NIS comics online for free comics. The free entry website of NIS comics login page Jun 12, 2025 pm 08:18 PM

Nice Comics, an immersive reading experience platform dedicated to creating for comic lovers, brings together a large number of high-quality comic resources at home and abroad. It is not only a comic reading platform, but also a community that connects comic artists and readers and shares comic culture. Through simple and intuitive interface design and powerful search functions, NES Comics allows you to easily find your favorite works and enjoy a smooth and comfortable reading experience. Say goodbye to the long waiting and tedious operations, enter the world of Nice comics immediately and start your comic journey!

Frog Man Online Viewing Entrance Man Frog Man (Web Page Entrance) Watch Online Frog Man Online Viewing Entrance Man Frog Man (Web Page Entrance) Watch Online Jun 12, 2025 pm 08:06 PM

Frogman Comics has become the first choice for many comic lovers with its rich and diverse comic resources and convenient and smooth online reading experience. It is like a vibrant pond, with fresh and interesting stories constantly emerging, waiting for you to discover and explore. Frog Man comics cover a variety of subjects, from passionate adventures to sweet love, from fantasy and science fiction to suspense reasoning, no matter which genre you like, you can find your favorite works here. Its simple and intuitive interface design allows you to easily get started, quickly find the comics you want to read, and immerse yourself in the exciting comic world.

Baozi Comics (Entrance)_ Baozi Comics (New Entrance) 2025 Baozi Comics (Entrance)_ Baozi Comics (New Entrance) 2025 Jun 05, 2025 pm 04:18 PM

Here, you can enjoy the vast ocean of comics and explore works of various themes and styles, from passionate young man comics to delicate and moving girl comics, from suspenseful and brain-burning mystery comics to relaxed and funny daily comics, there is everything, and there is always one that can touch your heartstrings. We not only have a large amount of genuine comic resources, but also constantly introduce and update the latest works to ensure that you can read your favorite comics as soon as possible.

b An latest registered address_How to register b An exchange b An latest registered address_How to register b An exchange May 26, 2025 pm 07:12 PM

The latest official website of 2025b Announce is: https://www.marketwebb.co/zh-CN/join?ref=507720986&amp;type=wenzi; Binance Exchange is a global cryptocurrency exchange that serves 180 countries and regions including North America, Europe, Taiwan, the Middle East, Hong Kong, and Malaysia. It provides more than 600 cryptocurrencies and has 270 million registered users worldwide.

See all articles