码迷,mamicode.com
首页 > 微信 > 详细

微信公众号智能绑定功能实现(2014年10月24日 更新)

时间:2014-10-24 16:38:53      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:智能绑定   公众号智能绑定   微信智能绑定   微信开发   

微信公众号智能绑定功能实现(2014年10月24日 更新)

继微信企业号发布后,腾讯修改了公众号的接入方式,在之前的基础上添加了2个表单,之前版本的智能绑定失效了!
bubuko.com,布布扣
在文章 微信公众号之智能绑定实现初始版本  的基础上修改,新增腾讯这次增加的表单,本次新增的表单有:

encoding_aeskey :EncodingAESKey(消息加解密密钥,长度43位!)

callback_encrypt_mode: 消息加解密方式(0:明文模式、1:兼容模式、3:安全模式(推荐))


operation_seq:此值可以不要,post参数的时候显示这个,是有规律的数字(如:202699977)!

此处附表单截图:
bubuko.com,布布扣

在文章 微信公众号之智能绑定实现初始版本  的基础上修改类 SmartBindUtil.class 的setDevServiceUrl()方法,具体代码如下:

/**
 * 设置开发模式,服务器回调
 * 
 * @param url
 * @param callback_token
 * @return
 */
public Result<Integer> setDevServiceUrl(String url, String callback_token) {
	Result<Integer> result = new Result<Integer>();
	int staus = login();
	if (staus == HttpStatus.SC_OK) {
		isLogin = true;
		PostMethod post = new PostMethod(DEV_SERVICE_URL + token);
		setHeader(post);
		NameValuePair[] params = new NameValuePair[] {
				new NameValuePair("url", "" + url),
				new NameValuePair("callback_token", callback_token),
				new NameValuePair("encoding_aeskey", "aZpGSA7ctX4OfCI7ki8gJRwzw8APJJUu7ro8OHFBTw5"),
				new NameValuePair("callback_encrypt_mode", "0"),
				new NameValuePair("operation_seq", "202699977")};
		post.setRequestBody(params);
		try {
			log.info("正在设置公众平台回调...");
			staus = client.executeMethod(post);
			if (staus == HttpStatus.SC_OK) {
				log.info("服务器连接成功");
				String res = post.getResponseBodyAsString();
				// TODO............
				System.out.println("res========" + res);
				JSONObject retcode = JSON.parseObject(res);
				JSONObject base_resp=retcode.getJSONObject("base_resp");
				staus = Integer.parseInt(base_resp.getString("ret"));
				result.setObject(Integer.parseInt(base_resp.getString("ret")));
				result.setMsg(base_resp.getString("msg"));
			} else {
				result.setObject(staus);
				result.setMsg("网络连接错误,请稍后再试");
			}
		} catch (Exception e) {
			log.info(e.getMessage(), e);
			result.setObject(staus);
			result.setMsg("网络连接错误,请稍后再试");
		} finally {
			post.releaseConnection();
		}
	} else {
		result.setObject(staus);
		result.setMsg("服务器登陆失败,请稍后再试");
	}
	return result;
}



测试结果图:

bubuko.com,布布扣


交流QQ群:89714226 点击链接加入群【微信企业号开发交流】:http://jq.qq.com/?_wv=1027&k=MZRJ0J

转载注明出处,以免惨不忍睹!

说明:如需绑定订阅号修改代码中获取appid 和 appsecret 的代码!


微信公众号智能绑定功能实现(2014年10月24日 更新)

标签:智能绑定   公众号智能绑定   微信智能绑定   微信开发   

原文地址:http://blog.csdn.net/omsvip/article/details/40427941

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!