Quellcode durchsuchen

企业微信生成aesKey的接口

fancy vor 5 Jahren
Ursprung
Commit
d56bcdbbb3

+ 52 - 0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/qiyeweixin/ActionCallbackAESKey.java

@@ -0,0 +1,52 @@
+package com.x.program.center.jaxrs.qiyeweixin;
+
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.gson.GsonPropertyObject;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import org.apache.commons.codec.binary.Base64;
+
+import java.util.UUID;
+
+/**
+ * Created by fancyLou on 2020-10-26.
+ * Copyright © 2020 O2. All rights reserved.
+ */
+public class ActionCallbackAESKey extends BaseAction {
+
+    private static Logger logger = LoggerFactory.getLogger(ActionCallbackAESKey.class);
+
+    ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
+        ActionResult<Wo> result = new ActionResult<Wo>();
+        String encodingAesKey = Base64.encodeBase64String(UUID.randomUUID().toString().replaceAll("-","").getBytes());
+        logger.info("生成企业微信回调用的 AESKey "+ encodingAesKey);
+        if (encodingAesKey.contains("=")) {
+            encodingAesKey = encodingAesKey.substring(0, encodingAesKey.lastIndexOf("="));
+        }
+        Wo wo = new Wo();
+        wo.setKey(encodingAesKey);
+        result.setData(wo);
+        return result;
+    }
+
+
+    public static class Wo extends GsonPropertyObject {
+
+
+        private static final long serialVersionUID = 6701949833103126778L;
+
+
+        @FieldDescribe("EncodingAESKey")
+        private String key;
+
+        public String getKey() {
+            return key;
+        }
+
+        public void setKey(String key) {
+            this.key = key;
+        }
+    }
+}

+ 18 - 0
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/qiyeweixin/QiyeweixinAction.java

@@ -64,6 +64,24 @@ public class QiyeweixinAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 	}
 
 
+	@JaxrsMethodDescribe(value = "获取企业微信回调的EncodingAESKey.", action = ActionCallbackAESKey.class)
+	@GET
+	@Path("get/callback/aes")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void syncOrganizationCallbackEncodingAESKeyGet(@Suspended final AsyncResponse asyncResponse,
+														  @Context HttpServletRequest request) {
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		ActionResult<ActionCallbackAESKey.Wo> result = new ActionResult<>();
+		try {
+			result = new ActionCallbackAESKey().execute(effectivePerson);
+		}catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
 //	@Path("sync/organization/callback")
 //	@Path("sync/organization/callback")
 //	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 //	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 //	@Consumes(MediaType.APPLICATION_JSON)
 //	@Consumes(MediaType.APPLICATION_JSON)