微信開發系列之一 - 微信公眾號開發的開發環境搭建
文章系列目錄
- Wechat development series 1 – setup your development environment
- Wechat development series 2 – development Q&A service using nodejs
- Wechat development series 3 – Trigger C4C Account creation in Wechat app
- Wechat development series 4 – Send C4C Data change notification to Wechat app
- Wechat development series 5 – embedded your UI5 application to Wechat app
- Wechat development series 6 – Retrieve Wechat User info via oAuth2 and display it in UI5 application
- Wechat development series 7 – use Redis to store Wechat conversation history
- Wechat development series 8 – Map integration
- Wechat development series 9 – Create C4C Social Media Message and Service within Wechat app
- Wechat development series 10 – Use Wechat app to receive Service Request reply made from C4C
Tencent’s WeChat, a social networking app with more than 760 million monthly active users, is becoming a dominant mobile channel connecting businesses and customers. This series will illustrate how to do some development on Wechat so it could interact with SAP product like SAP Cloud for Customer.
Prerequisite
(1) You should have already registered an subscription account in Wechat Official Account platform: https:// mp.weixin.qq.com (2) You should have basic knoledge about nodejs development. Detail steps for environment setup Log on to Official Account platform https:// mp.weixin.qq.com , menu Development->Basic configuration,
The most important setting here is the server url, where the custom logic of your Wechat official subscription account is hosted.
In this series, I will use nodejs plus Heroku to host the server. This server is responsible to serve the request which is delegated by Wechat platform issued originally by your Wechat official subscription account’s followers. Before Wechat platform will really delegate user request to this server, you must first pass the verification defined by Wechat’s development guide: https:// mp.weixin.qq.com/wiki? t=resource/res_main&id=mp1472017492_58YV5 Unfortunately the verification flow chart in the guide is drawn with Chinese text:
And the provided sample code is written by Python, so here I will provide a nodejs solution instead.
As long as you press “Submit” button, Wechat platform will send a http request to the server specified via this URL:
The http request looks like below:
https:///?signature=096abd439b41f9610aeabe2d7534084fd8dafa20&echostr=16168327802220428137×tamp=1512810825&nonce=384289189
The responsibility of your server is then to calculate a result based on your subscription account token, the timestamp and the nonce field, and compare it with the echostr passed with the request url. If the comparison result is not equal, you will see error message “Token authentication failed”.
Only after your server has passed the verification then it is ready for subsequent development.
Below is the step how to develop your server to pass the verification.
(1) Create a new nodejs project with the following package.json. The highlighted part is relevant for server verification.
(2) Implement server.js with following source code:
var express = require('express');var routesEngine = require('./index.js'); var app = express();routesEngine(app);app.listen(process.env.PORT || 3000, function () {
console.log('Listening on port, process.cwd(): ' + process.cwd() );});In implementation of index.js, now we need to implement verification process:var request = require('request');var jsSHA = require('jssha');module.exports = function (app) {
app.route('/').get(function(req,res){
var token="jerry"; // replace it with your own token var signature = req.query.signature,
timestamp = req.query.timestamp,
echostr = req.query.echostr,
nonce = req.query.nonce;
oriArray = new Array();
oriArray[0] = nonce;
oriArray[1] = timestamp;
oriArray[2] = token;
oriArray.sort();
var original = oriArray.join('');
var shaObj = new jsSHA("SHA-1", 'TEXT');
shaObj.update(original);
var scyptoString = shaObj.getHash('HEX');
console.log("calculated string: " + scyptoString);
if (signature == scyptoString) {
res.send(echostr);
} else {
res.send('bad token');
}
});};
(3) deploy this nodejs application to Heroku. For detail steps, please refer to my blog Step by step to host your UI5 application in Heroku.
Once done, perform the verification in Wechat Official Account platform.
Then in Heroku application console we can see that the signature passed from Wechat platform is equal to the value calculated in our nodejs server, as a result the verification is finished successfully:
You can see now the Server configuration in Wechat platform is marked as enabled, which is ready for subsequent development.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2724662/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 微信公眾號開發
- Nodejs微信公眾號開發NodeJS
- .net開發微信公眾號
- 微信公眾號開發-分享
- 微信程式開發系列教程(一)開發環境搭建開發環境
- Python開發微信公眾號後臺(系列二)Python
- 微信公眾號開發5-自定義選單-微信開發phpPHP
- SAP系統和微信整合的系列教程之一:微信開發環境的搭建開發環境
- 微信公眾號開發之坑(一)
- Python+Tornado開發微信公眾號Python
- PHP微信公眾號開發——公共方法PHP
- 【Java】微信公眾號開發筆記Java筆記
- Laravel+easywechat 開發微信公眾號Laravel
- 微信小程式開發系列(一) :開發環境搭建和微信小程式的檢視設計與開發微信小程式開發環境
- 在 Ubuntu 18.04 上 搭建微信小程式和公眾號應用開發環境Ubuntu微信小程式開發環境
- 微信公眾號開發 —— 微信網頁授權小記網頁
- 微信公眾號測試號開發小結
- 微信公眾號開發推送事件排重事件
- 微信公眾號支付開發手記(node)
- 記一次微信公眾號開發
- 微信公眾號開發Django JSSDK授權DjangoJS
- 微信公眾號開發(一)基礎配置
- Spring Boot 開發微信公眾號後臺Spring Boot
- 微信公眾號開發之客服訊息
- NodeJS介紹以及開發微信公眾號ExampleNodeJS
- 微信公眾號開發Django 網頁授權Django網頁
- 微信公眾號開發教程(一) 驗證接入
- 微信公眾號Java開發記錄(一)接入Java
- Nodejs開發微信公眾號中控服務NodeJS
- 微信公眾號開發-後端demo(隨錄)後端
- 微信程式開發系列教程(四)使用微信API建立公眾號自定義選單API
- 【微信部落】tp5+ionic開發微信公眾號商城系統
- 微信公眾號開發系統入門教程(公眾號註冊、開發環境搭建、access_token管理、Demo實現、natapp外網穿透)開發環境APP穿透
- uni-app微信公眾號web JS-SDK開發之一接入APPWebJS
- 微信公眾號快速開發(二)專案搭建與被動回覆
- 開發微信公眾號基本配置引數錯誤
- 微信公眾號支付開發全過程(Java 版)Java
- 微信公眾號影片直播系統開發介紹