微信开发接口配置和Web开发工具
来源:互联网 发布:it职业技术学校 编辑:程序博客网 时间:2024/05/22 00:44
微信公众平台开发者文档:http://mp.weixin.qq.com/wiki/home/index.html
首先申请一个微信公众开发测试账号:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
申请后会提供appID和appsecret,你需要在自己的代码中添加接口配置的处理。
但此处URL必须为一个公网地址,且使用80端口,这就涉及到之前讲到的公网映射的方式。通常使用ngrok,注册后获得authtoken并配置,使用ngrok http <port>即可将指定端口映射到公网80端口。
接口配置的java示例:(参考Journey的博客)
@WebServlet(urlPatterns = "/wx", name = "wxHouseKeeperServlet") public class HouseKeeper extends HttpServlet { public static final String TOKEN = "mzmzo"; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { // 开发者提交信息后,微信服务器将发送GET请求到填写的服务器地址URL上,GET请求携带参数 String signature = request.getParameter("signature");// 微信加密签名(token、timestamp、nonce。) String timestamp = request.getParameter("timestamp");// 时间戳 String nonce = request.getParameter("nonce");// 随机数 String echostr = request.getParameter("echostr");// 随机字符串 PrintWriter out = response.getWriter(); // 将token、timestamp、nonce三个参数进行字典序排序 String[] params = new String[] { TOKEN, timestamp, nonce }; Arrays.sort(params); // 将三个参数字符串拼接成一个字符串进行sha1加密 String clearText = params[0] + params[1] + params[2]; String algorithm = "SHA-1"; String sign = new String( Hex.encodeHex(MessageDigest.getInstance(algorithm).digest((clearText).getBytes()), true)); // 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 if (signature.equals(sign)) { response.getWriter().print(echostr); } } catch (Exception e) { e.printStackTrace(); } } }
此处TOKEN与网页中填写的Token一致即可
接下来配置“网页授权获取用户基本信息”
注意填写时不用加http://,只填写域名即可。
完成后扫描下方二维码即可关注自己的公众测试号,网页中会显示关注用户的Openid。
下载微信Web开发工具,即可模拟手机调试
完成登录和绑定后,开发者就可以开始调试微信网页授权,在地址栏直接输入URL
示例: https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx841a97238d9e17b2&redirect_uri=http://cps.dianping.com/weiXinRedirect&response_type=code&scope=snsapi_base&state=type%3Dquan%2Curl%3Dhttp%3A%2F%2Fmm.dianping.com%2Fweixin%2Faccount%2Fhome
这里appid填写之前注册后得到的,redirect_uri指向自己的公网域名下的url,response_type为code,scope为snsapi_base表示静默授权,state填写uri后的mapping。注意这里的redirect_uri和state可能需要urlencode。
- 微信开发接口配置和Web开发工具
- 微信web开发工具
- 微信web开发工具
- 【微信开发】接口配置
- 微信开发接口配置
- 微信开发之web开发者工具
- 微信开发(web开发者工具)
- 微信web开发工具-授权登录
- 微信web开发调试工具
- 微信WEB开发调试工具
- 微信公众帐号开发-接口配置
- 微信web开发者工具、破解文件、开发文档和开发Demo下载
- 微信开发--微信分享等接口配置
- 微信接口开发
- 微信接口开发
- 微信开发接口
- 微信和支付宝接口开发
- 微信开发 web
- 深入浅出Spring(三) 五种通知
- 关于本地服务器怎么让外网访问到
- Codeforces 1C Ancient Berland Circus
- #define new DEBUG_NEW
- 从输入url到页面展示到底发生了什么
- 微信开发接口配置和Web开发工具
- 哈夫曼树算法实现
- 幸存者偏见
- 浅谈腾讯热更新开源框架xLua自定义Loader
- linux下解压命令大全
- iOS
- 1051. 复数乘法
- loadrunner中lr_wasted_time函数
- SCUT125 华为杯 D.笔芯回文 —— DP