4 changed files with 244 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||
package com.ccsens.tall.bean.dto; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: whj |
|||
* @time: 2020/6/17 11:04 |
|||
*/ |
|||
@Data |
|||
@ApiModel("wps相关请求参数") |
|||
public class WpsDto { |
|||
@ApiModel("获取文件元数据请求") |
|||
@Data |
|||
public static class FileInfo{ |
|||
@ApiModelProperty("请求签名") |
|||
@JsonProperty("_w_signature") |
|||
private String signature; |
|||
@ApiModelProperty("应用id") |
|||
@JsonProperty("_w_appid") |
|||
private String appId; |
|||
} |
|||
} |
@ -0,0 +1,119 @@ |
|||
package com.ccsens.tall.web; |
|||
|
|||
import io.swagger.annotations.*; |
|||
import lombok.Data; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.ServletRequest; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: whj |
|||
* @time: 2020/6/17 10:07 |
|||
*/ |
|||
@Api(tags = "wps相关权限") |
|||
@RestController |
|||
@RequestMapping("/v1/3rd") |
|||
public class WpsController { |
|||
|
|||
@ApiOperation(value = "获取文件元数据", notes = "在预览或编辑的时候,通过接口校验权限并获取文件信息") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@GetMapping(value = "file/info", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileInfo(){ |
|||
|
|||
|
|||
|
|||
return null; |
|||
} |
|||
|
|||
@ApiOperation(value = "获取用户信息", notes = "在编辑的时候获取编辑过此文件的用户信息,展示在协作记录里面") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PostMapping(value = "user/info", produces = {"application/json;charset=UTF-8"}) |
|||
public String userInfo(HttpServletRequest request){ |
|||
String token = request.getHeader("x-wps-weboffice-token"); |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@ApiOperation(value = "上传文件新版本", notes = "编辑完保存回对应云盘") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PostMapping(value = "file/save", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileSave(){ |
|||
return null; |
|||
} |
|||
|
|||
@ApiOperation(value = "通知文件有那些人在协作协作", notes = "通知此文件目前有那些人正在协作") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PostMapping(value = "file/online", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileOnline(){ |
|||
return null; |
|||
} |
|||
|
|||
@ApiOperation(value = "获取特定版本的文件信息", notes = "在回滚版本的时候需要获取历史版本的文件信息") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@GetMapping(value = "file/version/{version}", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileVersion(@PathVariable("version") String version){ |
|||
return null; |
|||
} |
|||
|
|||
@ApiOperation(value = "文件重命名", notes = "当用户有重命名权限时,重命名时调用的接口") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PutMapping(value = "file/rename", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileRename(){ |
|||
return null; |
|||
} |
|||
|
|||
@ApiOperation(value = "获取所有历史版本文件信息", notes = "显示在历史版本列表中") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PostMapping(value = "file/history", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileHistory(){ |
|||
return null; |
|||
} |
|||
@ApiOperation(value = "新建文件", notes = "通过模板新建需要提供的接口") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PostMapping(value = "file/new", produces = {"application/json;charset=UTF-8"}) |
|||
public String fileNew(){ |
|||
return null; |
|||
} |
|||
@ApiOperation(value = "通知", notes = "打开文件时返回通知的接口") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
@PostMapping(value = "onnotify", produces = {"application/json;charset=UTF-8"}) |
|||
public String onnotify(){ |
|||
return null; |
|||
} |
|||
|
|||
@Data |
|||
@ApiModel("wps通用请求头参数") |
|||
private static class WpsHeader{ |
|||
@ApiModelProperty("用户代理") |
|||
private String userAgent; |
|||
@ApiModelProperty("校验身份的token") |
|||
private String token; |
|||
@ApiModelProperty("文件id") |
|||
private String fileId; |
|||
|
|||
/** |
|||
* 获取请求头(由weboffice开放平台写入) |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
public WpsHeader getHeader(HttpServletRequest request) { |
|||
WpsHeader header = new WpsHeader(); |
|||
header.setUserAgent(request.getHeader("User-Agent")); |
|||
header.setToken(request.getHeader("x-wps-weboffice-token")); |
|||
header.setFileId(request.getHeader("x-weboffice-file-id")); |
|||
return header; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,95 @@ |
|||
package com.ccsens.util; |
|||
|
|||
import cn.hutool.core.codec.Base64; |
|||
|
|||
import javax.crypto.Mac; |
|||
import javax.crypto.spec.SecretKeySpec; |
|||
import java.io.UnsupportedEncodingException; |
|||
import java.net.URLEncoder; |
|||
import java.security.InvalidKeyException; |
|||
import java.security.NoSuchAlgorithmException; |
|||
import java.util.*; |
|||
|
|||
|
|||
/** |
|||
* @description: |
|||
* @author: whj |
|||
* @time: 2020/6/17 9:59 |
|||
*/ |
|||
public class WpsSignature { |
|||
|
|||
public static void main(String args[]) throws UnsupportedEncodingException { |
|||
Map<String, String> paramMap= new HashMap<>(); |
|||
paramMap.put("_w_appid", "123456"); |
|||
paramMap.put("_w_fname", "222.docx"); |
|||
paramMap.put("_w_userid", "id1000"); |
|||
String signature = getSignature(paramMap,"7890"); |
|||
System.out.println(getUrlParam(paramMap) + "&_w_signature=" + signature); |
|||
} |
|||
|
|||
|
|||
|
|||
private static String getUrlParam(Map<String, String> params) throws UnsupportedEncodingException { |
|||
StringBuilder builder = new StringBuilder(); |
|||
for (Map.Entry<String, String> entry : params.entrySet()) { |
|||
if (builder.length() > 0) { |
|||
builder.append('&'); |
|||
} |
|||
builder.append(URLEncoder.encode(entry.getKey(), "utf-8")).append('=').append(URLEncoder.encode(entry.getValue(), "utf-8")); |
|||
} |
|||
return builder.toString(); |
|||
} |
|||
|
|||
private static String getSignature(Map<String, String> params, String appSecret) { |
|||
List<String> keys=new ArrayList(); |
|||
for (Map.Entry<String, String> entry : params.entrySet()) { |
|||
keys.add(entry.getKey()); |
|||
} |
|||
|
|||
// 将所有参数按key的升序排序
|
|||
Collections.sort(keys, new Comparator<String>() { |
|||
@Override |
|||
public int compare(String o1, String o2) { |
|||
return o1.compareTo(o2); |
|||
} |
|||
}); |
|||
|
|||
// 构造签名的源字符串
|
|||
StringBuilder contents=new StringBuilder(""); |
|||
for (String key : keys) { |
|||
if (key=="_w_signature"){ |
|||
continue; |
|||
} |
|||
contents.append(key+"=").append(params.get(key)); |
|||
System.out.println("key:"+key+",value:"+params.get(key)); |
|||
} |
|||
contents.append("_w_secretkey=").append(appSecret); |
|||
|
|||
// 进行hmac sha1 签名
|
|||
byte[] bytes= hmacSha1(appSecret.getBytes(),contents.toString().getBytes()); |
|||
//字符串经过Base64编码
|
|||
String sign= Base64.encode(bytes); |
|||
try { |
|||
sign = URLEncoder.encode( sign, "UTF-8"); |
|||
} catch (UnsupportedEncodingException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
System.out.println(sign); |
|||
return sign; |
|||
} |
|||
|
|||
public static byte[] hmacSha1(byte[] key, byte[] data) { |
|||
try { |
|||
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1"); |
|||
Mac mac = Mac.getInstance(signingKey.getAlgorithm()); |
|||
mac.init(signingKey); |
|||
return mac.doFinal(data); |
|||
} |
|||
catch (NoSuchAlgorithmException e) { |
|||
e.printStackTrace(); |
|||
} catch (InvalidKeyException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
} |
Loading…
Reference in new issue