微信公众号第三方平台全网发布测试程序
2015-07-07 23:09
761 查看
1:微信官方文档部分
全网发布测试在平台接收微信回调的servlet的doPost方法中,增加代码:
[code]//全网发布单元测试 if("gh_3c884a361561".equals(wechatRequest.getToUserName())){ FullWebPublishUtil.test(wechatRequest, response); }
FullWebPublishUtil全网发布测试工具类
[code]import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import weixin.wechat4j.message.CustomerMsg; import weixin.wechat4j.request.WechatRequest; /** * 微信公众号第三方平台:全网发布测试程序 * 创建:刘彦亮 2015年7月7日 */ public class FullWebPublishUtil { public static String query_auth_code = ""; public static void test(WechatRequest wechatRequest, HttpServletResponse response){ String fromUser = wechatRequest.getFromUserName(); String content = wechatRequest.getContent(); System.out.println("content======>"+content); String content_reply1 = ""; String content_reply2 = ""; String content_reply3 = ""; //1、模拟粉丝触发专用测试公众号的事件 if(StringUtils.isNotNull(wechatRequest.getEvent())){ content_reply1 = wechatRequest.getEvent() + "from_callback"; System.out.println("content_reply1======>"+content_reply1); CustomerMsg customerMsg = new CustomerMsg(fromUser,"wizincloud"); customerMsg.sendText(content); } //2、模拟粉丝发送文本消息给专用测试公众号 if(StringUtils.isNotNull(content) && "TESTCOMPONENT_MSG_TYPE_TEXT".equals(content)){ content_reply2 = "TESTCOMPONENT_MSG_TYPE_TEXT_callback"; //3、模拟粉丝发送文本消息给专用测试公众号 }else if(StringUtils.isNotNull(content) && content.contains("QUERY_AUTH_CODE")){ int index = content.indexOf(":"); content = content.substring(index+1); query_auth_code = content; System.out.println("query_auth_code======>"+query_auth_code); content_reply3 = query_auth_code+"_from_api"; } // 使用授权码换取公众号的授权信息 String component_access_token = WeixinUtil.getComponentAccessToken(); String url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=" + component_access_token; Map<String, String> paraMap = new HashMap<String, String>(); paraMap.put("component_appid", Constants.WX_OPEN_APPID); paraMap.put("authorization_code", query_auth_code); JSONObject job = WeixinUtil.httpRequest(url, "POST", JSONObject.fromObject(paraMap).toString()); JSONObject authjob = (JSONObject) job.get("authorization_info"); String authorizer_appid = authjob.getString("authorizer_appid"); String authorizer_access_token = authjob.getString("authorizer_access_token"); System.out.println("authorizer_appid="+authorizer_appid); //获取access_token System.out.println("authorizer_access_token="+authorizer_access_token); CustomerMsg customerMsg = new CustomerMsg(fromUser,authorizer_access_token); //回复测试信息 if(StringUtils.isNotNull(content_reply1)){ customerMsg.sendText(content_reply1); } if(StringUtils.isNotNull(content_reply2)){ customerMsg.sendText(content_reply2); } if(StringUtils.isNotNull(content_reply3)){ customerMsg.sendText(content_reply3); } } }
3:微信开放平台全网发布
相关文章推荐
- 小商家为何要逃离微信公众平台
- [一车大师]微信运营心得
- [一车大师]微信公众平台开发入门
- C#/ASP.NET MVC微信公众号接口开发之从零开发(一) 接入微信公众平台
- 基于nodejs 的微信 JS-SDK 简单应用
- Java 基本常识+概述+环境变量配置+Hello World小程序
- Android第四十二期 - 关于微信手势退出Activity的操作
- Android第四十二期 - 关于微信手势退出Activity的操作
- 微信移动用户他入组
- 如何判断微信内置浏览器
- 微信公众平台网页获取用户OpenID方法
- 微信支付v3发布到iis时的证书问题(转)
- 可穿戴设备(CC2541)上微信(2)
- 2015年微信公众号媒体价值研究报告
- ecshop第三方登陆之微信登录
- 可穿戴设备(CC2541)上微信(1)
- 半透明父视图,小程序不透明
- 微信jssdk
- 微信联名登陆 - 定时刷新服务号、订阅号access_token有效时间
- 微信企业号开发之-如何获取secret 序列号