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

  • 相关阅读:
    StrCopy、StrCat、StrPas
    WinAPI: FlashWindow 闪烁窗口
    WinAPI: SetVolumeLabel 设置磁盘卷标
    WinAPI: GetActiveWindow 获取当前活动窗口的句柄
    WinAPI: SetCurrentDirectory、GetCurrentDirectory 设置与获取当前目录
    WinAPI: CreateDirectoryEx 根据模版建立文件夹
    WinAPI: CreateDirectory 建立文件夹
    WinAPI: RemoveDirectory 删除空目录
    WinAPI: GetLogicalDriveStrings 获取系统中存在的逻辑驱动器字符串
    filer.js: 一个 Unix 命令风格的 HTML 5 FileSystem API 封装 V2EX
  • 原文地址:https://www.cnblogs.com/cw828/p/11660525.html
Copyright © 2011-2022 走看看