• 微信公众号转发网页


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

  • 相关阅读:
    php 魔术方法
    有用的函数系统采集(一)
    php后期静态绑定
    php对象引用及序列化
    php文件操作
    复习mysql视图总结
    jQuery调用WebService详解
    这个网站的界面描述甚好,我喜欢
    喜欢和技术有关的一切~
    Introduction
  • 原文地址:https://www.cnblogs.com/cw828/p/11660525.html
Copyright © 2020-2023  润新知