/** * 获取登录企业号官网的url * * @param corpId <font color="red">oauth授权的corpid</font> * @param targetType 登录跳转到企业号后台的目标页面 * @param agentId 授权方应用id 小余1时则不传递 * @return 登陆URL * @see <a * href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%AE%98%E7%BD%91%E7%9A%84url">获取登录企业号官网的url</a> * @throws WeixinException */ public String getLoginUrl(String corpId, LoginTargetType targetType, int agentId) throws WeixinException { Token token = cacheStorager.lookup(getLoginTicketCacheKey(corpId)); if (token == null || StringUtil.isBlank(token.getAccessToken())) { throw new WeixinException("maybe oauth first?"); } String oauth_loginurl_uri = getRequestUri("oauth_loginurl_uri"); JSONObject obj = new JSONObject(); obj.put("login_ticket", token.getAccessToken()); obj.put("target", targetType.name()); if (agentId > 0) { obj.put("agentid", agentId); } WeixinResponse response = weixinExecutor.post( String.format(oauth_loginurl_uri, providerTokenManager.getAccessToken()), obj.toJSONString()); return response.getAsJson().getString("login_url"); }
/** * 生成带参数的二维码 * * @param parameter 二维码参数 * @return 二维码结果对象 * @throws WeixinException * @see com.foxinmy.weixin4j.mp.model.QRResult * @see com.foxinmy.weixin4j.mp.model.QRParameter * @see <a href="http://mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html">生成二维码</a> */ public QRResult createQR(QRParameter parameter) throws WeixinException { Token token = tokenHolder.getToken(); String qr_uri = getRequestUri("qr_ticket_uri"); WeixinResponse response = weixinExecutor.post(String.format(qr_uri, token.getAccessToken()), parameter.getContent()); QRResult result = response.getAsObject(new TypeReference<QRResult>() {}); qr_uri = getRequestUri("qr_image_uri"); response = weixinExecutor.get(String.format(qr_uri, result.getTicket())); try { result.setContent(IOUtil.toByteArray(response.getBody())); } catch (IOException e) { throw new WeixinException(e); } return result; }