a. Introduction micro-channel public number
1. The number into service, subscription number, applets, corporate micro-channel;
2. When the user public micro-channel number message, will send information to the micro-channel server,
the public micro-channel number to save server administrator specified in rule management platform,
micro-channel server will be based on setting good rule areas and public No. interaction;
3. when the program is to develop their own, hoping to micro-channel server does not process the request,
but the request is pushed to our own program processes the request,
then returns the results to the micro-channel service WeChat server returns the results to the user;
. b development environment to build
1. develop a good program in your computer through the browser can be accessed directly;
another computer is no way to access, we can make these computers are connected
to the same local area network and then access via ip;
2. on the Internet the other person is not see the program that we developed, and starting the program sent to the cloud server;
we need to program needs and micro-channel server to do the docking in the development process,
if the micro-channel server can not find our program there is no way butt, so when developing,
we first need to do within the network penetration;
it penetrates the aim to make our project can be accessed by other computers on the Internet 3. intranet;
network penetration software: peanut shells, nat123, ngrok (free, not very stable)
within the network penetration principle:
4.ngrok: http: //www.ngrok.cc/
1. Download a registered account;
2. tunneled
protocol: http
name: just write;
before set domain: just write;
local port: localhost: 80 (local project access port)
other unwanted fill;
3. copy the tunnel id, start ngrok client;
. c Open Access
1. Develop ready access to
a public number to log micro-channel platform (need to modify the development of "basic configuration);.
b personal account under a lot of features are not available, micro-channel to provide a test account application.
(HTTPS: // mp.weixin.qq.com / -> service number - "development of the document -" began to develop - "No application interface testing);
. c access to micro-channel public platform, developers need to complete the following steps:
HTTPS: // developers .weixin.qq.com / DOC / offiaccount / Basic_Information / Access_Overview.html
1, fill in the server configuration
2, validation server address
3, according to business logic interface documentation
within 2.url network through the url + + project method name name
token: the code requires consistent and;
The relevant code
@RequestMapping("/index")
public String index(HttpServletRequest request) {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
System.out.println(signature+"\n"+timestamp+"\n"+nonce+"\n"+echostr);
if(check(timestamp,nonce,signature,TOKEN)) {
System.out.println("接入成功");
}else {
System.out.println("接入失败");
}
return "index";
}
/**
* 校验参数
* @param timestamp
* @param nonce
* @param signature
* @param token
* @return
*/
private boolean check(String timestamp, String nonce, String signature,String token) {
//1.将token、timestamp、nonce三个参数进行字典序排序
String [] str = {token,timestamp,nonce};
Arrays.sort(str);
//2)将三个参数字符串拼接成一个字符串进行sha1加密
String strs = str[0]+str[1]+str[2];
String mysig= sha1(strs);
System.out.println("mysig:---->"+mysig);
//3)开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
return mysig.equals(signature);
}
private String sha1(String strs) {
// TODO Auto-generated method stub
try {
//获取加密对象
MessageDigest md = MessageDigest.getInstance("sha1");
//加密处理
byte[] digest = md.digest(strs.getBytes());
//处理加密结果
char [] chars = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append((chars)[(b>>4)&15]);
sb.append(chars[b&15]);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}