| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package com.malk.rjk.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.malk.rjk.dto.CallbackBody;
- import com.malk.rjk.server.RjkServer;
- import com.malk.rjk.util.CryptUtil;
- import com.malk.rjk.util.SHA1;
- import com.malk.server.common.McR;
- import lombok.SneakyThrows;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.Map;
- import java.util.concurrent.CompletableFuture;
- @Slf4j
- @RestController
- @RequestMapping("/weiling")
- public class RJKController {
- private final static String TOKEN = "Re7szzfwkolU2TPZs59nkGEcGqehjF0F";
- private final static String ENCODING_AES_KEY ="Re7szzfwkolU2TPZs59nkGEcGqehjF0FuSCvxldv6dr";
- @Autowired
- private RjkServer rjkServer;
- /*如果该项目存在子项目继续查*/
- @SneakyThrows
- @PostMapping("/CustomerProfileSubmission")
- McR CustomerProfileSubmission(@RequestBody Map<String,String> data){
- // 先返回成功响应
- CompletableFuture.runAsync(() -> {
- try {
- Thread.sleep(5000);
- log.info("响应客户资料等待完成");
- rjkServer.H3UserToweiling(data);
- } catch (Exception e) {
- log.error("客户资料同步失败", e);
- }
- });
- return McR.success();
- }
- @SneakyThrows
- @PostMapping("/StoreOrderSubmission")
- McR StoreOrderSubmission(@RequestBody Map<String,String> data){
- // 先返回成功响应
- CompletableFuture.runAsync(() -> {
- try {
- Thread.sleep(5000);
- log.info("响应商机资料等待完成");
- rjkServer.H3BusinessToWeiling(data);
- } catch (Exception e) {
- log.error("商机资料同步失败", e);
- }
- });
- return McR.success();
- }
- /**
- * 回调服务 测试请求地址的合法性
- *
- * @param msgSignature 消息签名,msg_signature计算结合了企业填写的token、请求中的timestamp、nonce、echostr
- * @param timeStamp 时间戳
- * @param nonce 随机数
- * @param echoStr 加密字符串
- * @return
- */
- @GetMapping(value = "/callback")
- public String listen(@RequestParam("msg_signature") String msgSignature,
- @RequestParam("timestamp") String timeStamp,
- @RequestParam("nonce") String nonce,
- @RequestParam("echostr") String echoStr) {
- //通过token, timestamp. nonce, echostr四个参数生成签名
- String signature = SHA1.gen(TOKEN, timeStamp, nonce, echoStr);
- //如果签名相同,则解密echostr并返回
- if (signature.equals(msgSignature)) {
- CryptUtil util = new CryptUtil(ENCODING_AES_KEY);
- // System.out.println("解密成功"+util.decrypt(echoStr));
- return util.decrypt(echoStr);
- }
- return null;
- }
- /**
- * 回调服务示例 解密后包含回调信息
- *
- * @param msgSignature 消息签名,msg_signature计算结合了企业填写的token、
- * 请求中的timestamp、nonce、请求体中的encrypt_msg
- * @param timeStamp 时间戳
- * @param nonce 随机数
- * @param body 请求体(回调应用的appid、 加密信息encrypt_msg)
- * @return
- */
- @PostMapping(value = "/callback")
- public String listen(@RequestParam("msg_signature") String msgSignature,
- @RequestParam("timestamp") String timeStamp,
- @RequestParam("nonce") String nonce,
- @RequestBody CallbackBody body) {
- String encrypted = body.getEncrypt_msg();
- String signature = SHA1.gen(TOKEN, timeStamp, nonce, encrypted);
- if (signature.equals(msgSignature)) {
- CryptUtil util = new CryptUtil(ENCODING_AES_KEY);
- // msg中包含回调信息
- String msg = util.decrypt(encrypted);
- log.info("回调信息:msg={}", msg);
- // 解析JSON字符串为JSONObject
- JSONObject callbackJson = JSON.parseObject(msg);
- rjkServer.syncWeilingToH3yun(callbackJson);
- }
- return "success";
- }
- }
|