|
|
@@ -0,0 +1,64 @@
|
|
|
+package com.inspur.customer.web.controller.keyclaok;
|
|
|
+
|
|
|
+import com.alibaba.cola.dto.Response;
|
|
|
+import com.alibaba.cola.dto.SingleResponse;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.inspur.customer.service.client.keycloak.KeycloakService;
|
|
|
+import com.inspur.customer.service.client.wechat.IWeChatService;
|
|
|
+import com.inspur.customer.service.dto.SubscribeDto;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 微信模块
|
|
|
+ * @author wangbo13
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@EnableScheduling
|
|
|
+@RequestMapping("/keycloak")
|
|
|
+public class KeycloakController {
|
|
|
+
|
|
|
+ @Value("${system.appKey}")
|
|
|
+ private String appKey;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private KeycloakService keycloakService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private IWeChatService iWeChatService;
|
|
|
+
|
|
|
+ @PostMapping("update/user")
|
|
|
+ public Response updateUser(@RequestBody String json){
|
|
|
+ SubscribeDto subscribe = JSONObject.parseObject(json, SubscribeDto.class);
|
|
|
+ if(StringUtils.isEmpty(subscribe.getUserId())){
|
|
|
+ return Response.buildFailure("404","userId不能为空!");
|
|
|
+ }
|
|
|
+ keycloakService.updateAttribute(subscribe.getUserId(), "wechat" , subscribe.getOppenId());
|
|
|
+ return Response.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("query/ticket/{userId}")
|
|
|
+ public SingleResponse getTicket(@PathVariable("userId") String userId ,
|
|
|
+ @RequestHeader("Authorization") String authorization){
|
|
|
+ return SingleResponse.of(iWeChatService.queryTicket(appKey , userId, authorization));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0/10 * * * * ?")
|
|
|
+ public void askUserOppenId(){
|
|
|
+ for(String userId : keycloakService.getUserMap().keySet()){
|
|
|
+ String oppenId = iWeChatService.askUser(userId);
|
|
|
+ if(!StringUtils.isEmpty(oppenId)){
|
|
|
+ SubscribeDto dto = new SubscribeDto();
|
|
|
+ dto.setUserId(userId);
|
|
|
+ dto.setOppenId(oppenId);
|
|
|
+ this.updateUser(JSONObject.toJSONString(dto));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|