官方公开的开发文档,有几个坑,着重说一下踩坑的记录过程。
1、通过官方的客户端接口模拟程序获取前端参数:随机数和token
2、java程序调用官方sdk,postman请求测试:
3、贴出关键的java集成类:
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ewaycloud.jw.common.core.util.R;
import com.ewaycloud.jw.westone.dto.IdentityDTO;
import com.ewaycloud.jw.westone.verifyService.VerifyServiceSoapProxy;
import com.ewaycloud.jw.westone.verifyService_pkg.VerifyIdTRet;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jdt.internal.compiler.batch.Main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.misc.BASE64Encoder;import java.io.File;
import java.util.Base64;
import java.util.Random;
import java.util.UUID;
import java.util.Base64;@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/channel/westone")
public class WestoneController {@Autowiredprivate VerifyServiceSoapProxy verifyServiceSoapProxy;@PostMapping("/verifyIdentityTicket")public R verifyIdentityTicket(@RequestBody IdentityDTO identityDTO) {try {String challenge = identityDTO.getRandom();String identityTicket = identityDTO.getToken();String appServerID = "0";
// BASE64Encoder encoder = new BASE64Encoder();
// String data = encoder.encode(challenge.getBytes());
// System.out.println("==========data: "+data);verifyServiceSoapProxy.setEndpoint("http://159.61.64.241:8000");VerifyIdTRet ret = verifyServiceSoapProxy.verifyIdentityTicket(challenge,identityTicket,appServerID);JSONObject jsonObject = JSONUtil.xmlToJson(ret.getResult());System.out.println(jsonObject.toString());Integer result = jsonObject.getJSONObject("verifyIdentityTicketResult").getInt("result");System.out.println(result);return R.ok(jsonObject.getJSONObject("verifyIdentityTicketResult"));}catch (Exception e){e.printStackTrace();return R.failed("验签失败!");}}public static void main(String[] args) {//String challenge ="MTM4NDM5MjY1NTIyMjI3Mw==";// 创建一个随机数生成器Random random = new Random();// 创建一个字节数组,用于存储随机数byte[] randomBytes = new byte[20]; // 可以根据需要改变字节数组的大小// 填充随机字节random.nextBytes(randomBytes);// 将字节数组编码为base64字符串String base64Random = Base64.getEncoder().encodeToString(randomBytes);// 输出base64编码的随机数System.out.println(base64Random);//BASE64Encoder encoder = new BASE64Encoder();//String data = encoder.encode(challenge.getBytes());//System.out.println("==========data: "+data);}}