zoukankan      html  css  js  c++  java
  • 微信公众号转发网页

    public ResultData getCcessToken(String param) {
    RequestParam req = null;
    Map<String, Object> parmap = null;
    try {
    req = gm.jsonToAnyObject(param, RequestParam.class);
    parmap = req.getValueOfClz(Map.class);
    } catch (Exception e) {
    return UtilParm.resultData(0, "param is err", null);
    }
    //获取access_token
    String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxxxxxxxxxxxxxxxxx&secret=xxxxxxxxxxxxxxxx";
    String access_token = null;
    String jsapi_ticket = null;
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    try {
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    String strResult = EntityUtils.toString(response.getEntity());
    JSONObject jsonResult = new JSONObject(strResult);
    access_token = (String) jsonResult.get("access_token");
    }
    } catch (Exception e) {
    throw new RuntimeException("获取access_token出错"+e.getMessage());
    }
    //获取jsapi_ticket
    String url2 = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+access_token+"&type=jsapi";
    URI u = null;
    try {
    u = new URI(url2);
    } catch (URISyntaxException e) {
    throw new RuntimeException("jsapi_ticket地址出错"+e.getMessage());
    }
    request.setURI(u);
    try {
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    String strResult = EntityUtils.toString(response.getEntity());
    JSONObject jsonResult = new JSONObject(strResult);
    jsapi_ticket = (String) jsonResult.get("ticket");
    }
    } catch (Exception e) {
    throw new RuntimeException("获取jsapi_ticket出错"+e.getMessage());
    }
    SortedMap<String,String> map = new TreeMap<>();
    String timeStamp = TimeStampUtil.getTimeStamp();
    String noncestr = UUID.randomUUID().toString().replace("-", "").substring(0,16);
    map.put("jsapi_ticket", jsapi_ticket);
    map.put("noncestr", noncestr);
    map.put("timestamp", timeStamp);
    String str = parmap.get("url").toString();
    //反编译验证地址
    map.put("url", WxURLDecoderUtil.getResDecoderUtil(str));
    String wxSplit = WxSpliceUtil.getWxSplit(map);
    String shaEncode;
    try {
    //sha1加密
    shaEncode = SecuritySHA1Utils.shaEncode(wxSplit);
    } catch (Exception e) {
    throw new RuntimeException("获取shi加密失败");
    }
    map.put("appId", "xxxxxxxxxxxx");
    map.put("signature", shaEncode);
    return UtilParm.resultData(1, "ok", map);
    }

  • 相关阅读:
    淘宝IP地址库采集
    Android MediaCodec硬编兼容性测试方案
    《Tensorflow实战》之6.3VGGnet学习
    tensorflow问题集锦
    <tensorflow实战>之5.3实现进阶的卷积网咯
    CNN_minist
    tensorflow之MLP学习
    tensorflow学习之等价代码
    tensorflow学习之softmax regression
    NPE进一步学习
  • 原文地址:https://www.cnblogs.com/cw828/p/11660525.html
Copyright © 2011-2022 走看看