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);
    }

  • 相关阅读:
    HTML Strip Char Filter
    Creating a custom analyzer in ElasticSearch Nest client
    elasticsearch-analysis-pinyin
    ElasticSearch安装拼音插件 elasticsearch-analysis-pinyin
    Elasticsearch5.4 删除type
    Performs the analysis process on a text and return the tokens breakdown of the text
    Elasticsearch 5 Ik+pinyin分词配置详解
    线性可分支持向量机--SVM(1)
    感知机分类(perceptron classification)
    创建DateFrame的常用四种方式
  • 原文地址:https://www.cnblogs.com/cw828/p/11660525.html
Copyright © 2011-2022 走看看