文章系列目录

  • 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&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”.

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 tokenvar 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的原创文章,请关注公众号"汪子熙":

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

  1. 用java开发微信公众号:测试公众号与本地测试环境搭建(一)

    本文为原创,原始地址为:http://www.cnblogs.com/fengzheng/p/5023678.html 俗话说,工欲善其事,必先利其器.要做微信公众号开发,两样东西不可少,那就是要有一 ...

  2. 微信公众号开发-测试公众号账号及本地环境搭建(一)

    https://www.cnblogs.com/fengzheng/p/5023678.html 测试公众号 微信公众号有订阅号.服务号.企业号,在注册的时候看到这样的信息,只有订阅号可以个人申请,服 ...

  3. C#开发微信门户及应用(27)-公众号模板消息管理

    原文:C#开发微信门户及应用(27)-公众号模板消息管理 通过模板消息接口,公众号能向关注其账号的用户发送预设模板的消息.模板消息仅用于公众号向用户发送重要的服务通知,只能用于符合其要求的服务场景中, ...

  4. 微信公众号平台接口开发:发送客服消息

    官方接口介绍 发送文本信息 参数有4个, access_token这个就不用介绍了,就是之前得到的那个AccessToken,就是在这个接口里边当中参数用的 touser是关注了公众号的微信用户的op ...

  5. 微信公众号三方平台开发【全网发布及全网发布接入检测】

    经过之前系列内容过后,接下来的代微信公众号实现业务部分跟微信公众号开发业务逻辑一样,所以公众号其他业务功能部分后面我会单独整理一套相关内容,今天,咱们就来说说微信第三方平台开发的最后一步-- 全网发布 ...

  6. 微信开放平台 公众号第三方平台开发 教程一 平台介绍

    教程导航: 微信开放平台 公众号第三方平台开发 教程一 平台介绍 微信开放平台 公众号第三方平台开发 教程二 创建公众号第三方平台 微信开放平台 公众号第三方平台开发 教程三 一键登录授权给第三方平台 ...

  7. 微信公众号Java开发-笔记01【微信公众号介绍、开发环境搭建】

    学习网址:哔哩哔哩网站 微信公众号开发-Java版 微信公众号Java开发-笔记01[微信公众号介绍.开发环境搭建] 微信公众号Java开发-笔记02[] 微信公众号Java开发-笔记03[] 微信公 ...

  8. 微信公众号消息模板开发

    为什么80%的码农都做不了架构师?>>>    ##背景 新需求,需要在订单的时候给用户,商家,配送员发送想对于的微信消息模板,之前没有做过微信公众号相关的开发,这次就一并熟悉吧 # ...

  9. 限时团购,6.9折:《微信开发深度解析:公众号、小程序高效开发秘籍》推荐序

    全书由目 Senparc.Weixin SDK 作者苏震巍历时 2 年完成,涵盖了开发微信公众号及小程序需要用的的各项后端开发技能.技巧.避坑提示,以及 Senparc.Weixin SDK 微信公众 ...

  10. 微信开放平台公众号第三方平台开发 教程一 平台介绍

        微信现在火,火的如火如荼,给我们这些第三方的开发者带来了不少机会,相信现在有不少人在基于微信的公众平台在做二次开发,接下来会一系列的文章来介绍微信的另一种开发模式- 基于微信开发平台的公众号第 ...

最新文章

  1. Tony Qu的《WPF揭秘》情节
  2. 14个数据库的设计技巧 (来自Blogcn中我的窝)
  3. Hessian 原理分析--转
  4. SQL语句--INSERT INTO SELECT 语句用法示例
  5. Bootstrap 表单控件的状态
  6. 华为将联合京东举办线上发布会 或发布折叠屏手机
  7. 剑指offer面试题07. 重建二叉树(递归)(切片)
  8. php常量的声明和使用
  9. java horizontalbarchart_DOC-03-36 柱状图(Bar Chart)
  10. python你好代码-AI人工智能Python实现简单人机对话:你好,人类
  11. flex:1是什么意思
  12. 百度地图详解使用,显示自己的当前位置BaiduMap
  13. 2007第一天上班想哭
  14. Windows10 笔记本从睡眠状态唤醒时取消输入密码的方法
  15. python基础知识补充
  16. antd 覆盖css样式不生效(antd避坑)
  17. JDBC Statement RETURN_GENERATED_KEYS返回自动生成的ID
  18. 该升级了,阿里云Code升级Codeup | 云效
  19. MySQL简介,什么是数据库?
  20. colorkey唇釉是否安全_colorkey唇釉真假辨别_colourkey唇釉真伪

热门文章

  1. 一个小型数据库的核心组件
  2. 浅谈PopupWindow弹出菜单
  3. 透过【百度地图API】分析双闭包问题
  4. URL处理两个小工具方法
  5. Oracle基于布尔的盲注总结
  6. Spring web.xml详解
  7. SpringBoot实战 之 异常处理篇
  8. 我的asp入门宝典与您分享
  9. git对版本文件库的管理的工作目录
  10. 牛客网剑指offer编程实践51-66题