微信开发系列之一 - 微信公众号开发的开发环境搭建

简介: 微信开发系列之一 - 微信公众号开发的开发环境搭建

文章系列目录

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,


image.png


The most important setting here is the server url, where the custom logic of your Wechat official subscription account is hosted.


image.png


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:

image.png


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:


image.png


The http request looks like below:


https:///?signature=096abd439b41f9610aeabe2d7534084fd8dafa20&echostr=16168327802220428137&timestamp=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”.


image.png


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.


image.png


(2) Implement server.js with following source code:

image.png

(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:


image.png


You can see now the Server configuration in Wechat platform is marked as enabled, which is ready for subsequent development.


image.png

相关文章
|
3月前
|
小程序 PHP
微信公众号开发(一)打通服务器与微信之间的通信
说来惭愧PHP做了这么久,好像就没有从头开发过一个微信公众号,这次刚好有机会从头接入开发一个完整的公众号,也不能说完整,但是这些微信的接口我基本上都试一试~看看大概是什么情况。 首先:打通服务器与微信之间的通信。
38 0
|
2月前
|
XML Go 数据格式
【微信公众号开发】基于golang的公众号开发——接入消息自动回复接口
【微信公众号开发】基于golang的公众号开发——接入消息自动回复接口
45 0
|
3月前
|
前端开发 开发者
【微信公众号对接】有关签名一直报错,提示invalid signature问题(我的签名和使用微信开发者工具验证返回的签名的是一致的)但还是报错!!!
【微信公众号对接】有关签名一直报错,提示invalid signature问题(我的签名和使用微信开发者工具验证返回的签名的是一致的)但还是报错!!!
32 0
|
3月前
|
小程序 PHP 开发者
微信公众号开发(八)生成带参数二维码,以及将二维码下载至本地
微信的二维码真是个神奇的东西。在我们开发中,应用也是很多~ 用户扫描带场景值(参数)二维码时,可能推送以下两种事件:
50 1
|
3月前
|
XML 移动开发 小程序
微信公众号开发(七)微信h5跳转小程序及小游戏示例
最近公司做活动,需要从h5页面跳转至微信小游戏。 当时接到这个需求的时候,就在想,这玩意能相互跳转么? 后来百度了一下,还真行。
74 1
|
3月前
|
小程序 PHP
微信公众号开发(六)微信支付(发红包、企业支付到零钱)需要证书请求示例
这里最主要的就是curlpost请求的时候需要带上证书。否则请求会失败。
37 0
|
3月前
|
XML JSON 小程序
微信公众号开发(四)获取用户信息
获取用户信息,微信公众号提供了两种方式:
36 0
|
3月前
|
JSON 小程序 前端开发
微信公众号开发(三)设置底部菜单
填写access_token值,关于如何获取accesstoken值,请参见《微信公众号开发(二)微信公众号的access_token》 最后,将想要设置菜单的json写入body中。
48 0
|
3月前
|
JSON 小程序 数据库
微信公众号开发(二)微信公众号的access_token
微信对用户使用开放了很多的功能,如:自定义菜单接口、客服接口、获取用户信息接口、用户分组接口、群发接口,但是为了保证用户访问这些功能相对安全,每次访问都需要带上一个秘钥去验证身份。那么这个秘钥就是access_token。
44 0
|
4月前
|
前端开发
微信公众号开发实例之全局计时器的案例
微信公众号开发实例之全局计时器的案例
41 0