|
@@ -0,0 +1,60 @@
|
|
|
+package com.ruixuan.jiaoyang.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ruixuan.common.utils.Check;
|
|
|
+import com.ruixuan.common.utils.http.HttpUtil;
|
|
|
+import com.ruixuan.jiaoyang.service.IJiaoYangCallbackService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/jy/callback")
|
|
|
+public class JiaoYangCallbackController {
|
|
|
+ @Autowired
|
|
|
+ private IJiaoYangCallbackService jiaoYangCallbackService;
|
|
|
+ private static String appId = "ks690458118961229051";
|
|
|
+ private static String appSecret = "sqc2y31qQEY2E3AIWWvmCg";
|
|
|
+ private static String signSecret = "6ef1e2a231733bb0c38fb2bf0f50e45b";
|
|
|
+
|
|
|
+ @GetMapping("/oauth")
|
|
|
+ @ApiOperation(value = "骄阳-达人授权")
|
|
|
+ public String oauth(String code, String state) {
|
|
|
+ log.info("骄阳达人授权信息,code:{},state:{}", code, state);
|
|
|
+ if (Check.isNull(state)) {
|
|
|
+ return "授权失败,state信息为空";
|
|
|
+ }
|
|
|
+ if (Check.isNull(code)) {
|
|
|
+ return "授权失败,code信息为空";
|
|
|
+ }
|
|
|
+ String url = "https://openapi.kwaixiaodian.com/oauth2/access_token";
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("app_id", appId);
|
|
|
+ paramsMap.put("grant_type", "code");
|
|
|
+ paramsMap.put("app_secret", appSecret);
|
|
|
+ paramsMap.put("code", code);
|
|
|
+ String s = HttpUtil.httpGet(url, paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (Check.isNull(jsonObject)) {
|
|
|
+ return "授权失败,返回信息为空";
|
|
|
+ }
|
|
|
+ Integer result = jsonObject.getInteger("result");
|
|
|
+ if (result == 1) {
|
|
|
+ String accessToken = jsonObject.getString("access_token");
|
|
|
+ String refreshToken = jsonObject.getString("refresh_token");
|
|
|
+ Long promoterId = Long.valueOf(state);
|
|
|
+ jiaoYangCallbackService.replaceTokenInfo(promoterId, appId, appSecret, signSecret, accessToken, refreshToken);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return "授权失败,请联系技术解决";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "绑定成功";
|
|
|
+ }
|
|
|
+}
|