Forráskód Böngészése

认证通1.7.5版本功能开发

JiangChongBo 2 éve
szülő
commit
b3ff07d657

+ 6 - 0
pom.xml

@@ -323,6 +323,12 @@
             <artifactId>core</artifactId>
             <version>3.3.0</version>
         </dependency>
+        <!--HTTP请求上传文件时使用 -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+            <version>4.5.13</version>
+        </dependency>
 
 
         <dependency>

+ 11 - 0
src/main/java/com/caimei/annotation/WebHooks.java

@@ -0,0 +1,11 @@
+package com.caimei.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface WebHooks {
+}

+ 102 - 4
src/main/java/com/caimei/controller/admin/auth/AuthApi.java

@@ -3,6 +3,8 @@ package com.caimei.controller.admin.auth;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei.annotation.CurrentUser;
 import com.caimei.annotation.Idempotent;
+import com.caimei.annotation.WebHooks;
+import com.caimei.components.RedisService;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.po.CmBrandAuthPo;
 import com.caimei.model.po.SysUser;
@@ -10,6 +12,7 @@ import com.caimei.model.vo.AuthFormVo;
 import com.caimei.model.vo.AuthVo;
 import com.caimei.model.vo.ProductFormVo;
 import com.caimei.service.auth.AuthService;
+import com.caimei.utils.SmsUtils;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -18,15 +21,29 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 供应商API
@@ -42,7 +59,6 @@ import java.util.Map;
 public class AuthApi {
 
     private final AuthService authService;
-
     /**
      * 授权列表
      */
@@ -501,4 +517,86 @@ public class AuthApi {
         }
         return authService.getClubBindAuth(authUserId);
     }
+//-----------------------------------------------------上传视频至抖音-----------------------------------------------------------------------------------
+
+        /**
+         * 用户扫码授权,获取code值
+         * @param response
+         * @throws IOException
+         */
+        @GetMapping("/get/douying/code")
+        public ResponseJson getDouYingCode(HttpServletResponse response) throws IOException {
+            return authService.getDouYingCode(response);
+        }
+        /**
+         * 根据用户的code值获取AcessToken
+         * ccode 用户授权登录code
+         **/
+        @GetMapping("/get/douying/acesstoken")
+        public ResponseJson getDouYingAcessToken(String code) throws IOException {
+            return authService.getDouYingAcessToken(code);
+        }
+
+        /**
+         * h5的方式上传视频
+         * @return
+         * @throws IOException
+         */
+        @PostMapping("/upload/video/to/douyin")
+        public ResponseJson getclientToken(@RequestBody String params) throws IOException {
+            JSONObject paramsMap = JSONObject.parseObject(params);
+            String title = paramsMap.getString("title");
+            String videoPath = paramsMap.getString("videoPath");
+            return authService.getclientToken( title, videoPath);
+        }
+        /**
+         * 发布视频后通过webhook获取回调数据
+         * @param params
+         * @return
+         */
+        @PostMapping("/webhook")
+        @ResponseBody
+        @WebHooks
+        public Object tes(@RequestBody String params){
+            JSONObject paramsMap = JSONObject.parseObject(params);
+            System.out.println(paramsMap.getString("item_id"));
+            String content = paramsMap.getString("content");
+            JSONObject contentList = JSONObject.parseObject(content);
+            System.out.println(content);
+            String challenge = contentList.getString("challenge");
+            System.out.println(challenge);
+            String itemId=contentList.getString("item_id");
+            System.out.println(itemId);
+            String shareId=contentList.getString("share_id");
+            System.out.println(shareId);
+            Map<String ,String> map=new HashMap<>();
+            map.put("challenge",challenge);
+            map.put("item_id",itemId);
+            map.put("share_id",shareId);
+            return map;
+        }
+
+    /**
+     * 把抖音分享视频口令以短信推送给机构
+     *
+     * @return
+     */
+    @GetMapping("/sms")
+    public ResponseJson sms(String mobile,String content){//@RequestBody String params
+//         JSONObject jsonObject=JSONObject.parseObject(params);
+//         String mobile=jsonObject.getString("mobile");
+//         String content=jsonObject.getString("content");
+//         String authUser=jsonObject.getString("name");
+        // 短信类型:1通知短信,2验证码短信,3营销短信
+        String con=content.substring(0,content.indexOf("/")+1);
+        String cs=content.substring(content.indexOf("com")+3);
+         Integer type=1;
+         String kouLin="【上海品辉医疗科技有限公司】您在认证通抖音视频挑战赛发布的视频已成功上传至抖音平台,抖音分享口令为:"+con+" https://v.douyin.com"+cs+",您可复制该口令后去抖音平台打开【采美网提供技术支持】";
+        Boolean flag = SmsUtils.sendSms(type, mobile, kouLin);
+        if (flag){
+            return ResponseJson.success();
+        }else{
+            return ResponseJson.error("短信发送失败-----"+mobile);
+        }
+    }
 }

+ 50 - 0
src/main/java/com/caimei/service/aopservice/WebHooksService.java

@@ -0,0 +1,50 @@
+package com.caimei.service.aopservice;
+
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.annotation.WebHooks;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+
+/**
+ *
+ * 用于监听webhook事件(抖音授权,发布视频,解除授权)
+ */
+@Aspect
+@Component
+public class WebHooksService {
+    /**
+     *  层切点
+     */
+    @Pointcut("@annotation(webHooks)")
+    public void controllerAspect(WebHooks webHooks) {
+    }
+
+    @Before("controllerAspect(webHooks)")
+    public void After(JoinPoint pjp, WebHooks webHooks)  {
+        String body = null;
+        Object[] arguments = pjp.getArgs();
+        if(arguments.length!=0){
+            try {
+                body = arguments[0].toString();
+                System.out.println(body);
+                JSONObject jsonObject=JSONObject.parseObject(body);
+                String contnet=jsonObject.getString("content");
+                System.out.println(contnet);
+                JSONObject contnetlist=JSONObject.parseObject(contnet);
+                String challenge=contnetlist.getString("challenge");
+                System.out.println(challenge);
+                String itemId=contnetlist.getString("item_id");
+                System.out.println(itemId);
+                String shareId=contnetlist.getString("share_id");
+                System.out.println(shareId);
+                //获取itemid和shareid进行保存
+            }catch (Exception ex){
+                ex.printStackTrace();
+            }
+        }
+
+    }
+}

+ 21 - 0
src/main/java/com/caimei/service/auth/AuthService.java

@@ -9,6 +9,8 @@ import com.caimei.model.vo.TemplateVo;
 import com.github.pagehelper.PageInfo;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -137,4 +139,23 @@ public interface AuthService {
      * 获取可绑定机构机构信息
      * **/
     ResponseJson<List<AuthFormVo>> getClubBindAuth(Integer authUserId);
+
+    /**
+     * 用户扫码授权,获取code值
+     * @param response
+     * @return
+     * @throws IOException
+     */
+    ResponseJson getDouYingCode(HttpServletResponse response) throws IOException;
+    /**
+     * 根据用户的code值获取AcessToken
+     * ccode 用户授权登录code
+     **/
+    ResponseJson getDouYingAcessToken(String ccode) throws IOException;
+    /**
+     * h5的方式上传视频
+     * @return
+     * @throws IOException
+     */
+    ResponseJson getclientToken(String title,String videoPath) throws IOException;
 }

+ 419 - 0
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -1,5 +1,8 @@
 package com.caimei.service.auth.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.components.RedisService;
 import com.caimei.config.FastDfsClient;
 import com.caimei.mapper.cmMapper.AuthMapper;
 import com.caimei.mapper.cmMapper.AuthProductMapper;
@@ -13,10 +16,27 @@ import com.caimei.service.auth.ShopService;
 import com.caimei.service.auth.UploadService;
 import com.caimei.utils.Base64Util;
 import com.caimei.utils.ImageUtils;
+import com.caimei.utils.Md5Util;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
+import lombok.val;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,16 +45,24 @@ import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
+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.ResponseBody;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.Font;
 import java.io.*;
 import java.math.BigDecimal;
+import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.List;
@@ -88,6 +116,9 @@ public class AuthServiceImpl implements AuthService {
     @Value("${caimei.imageDomain}")
     private String imageDomain;
 
+    @Resource
+    private RedisService redisService;
+
     @Override
     public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty,
                                                       String mobile, Integer status, Integer starFlag, Integer auditStatus,
@@ -741,4 +772,392 @@ public class AuthServiceImpl implements AuthService {
         List<AuthFormVo> clubBindAuth = authMapper.getClubBindAuth(authUserId);
         return  ResponseJson.success(clubBindAuth);
     }
+//------------------------------------------v1.7.5上传视频至抖音---------------------------------------------------------------------------------------
+///用户授权(用于获取数据)
+    /**
+     * 用户扫码授权,获取code值
+     * @param response
+     * @return true :token没过期  false:token过期需重新授权
+     * @throws IOException
+     */
+    @Override
+    public ResponseJson getDouYingCode(HttpServletResponse response) throws IOException {
+        //验证是否是第一次登录(根据redis缓存中的token验证)
+        long dYaccessTok = redisService.getExpireTime("DYaccessToken");
+        boolean s=redisService.exists("DYaccessToken");
+       String s1= redisService.get("DyopenId").toString();
+//        if(!redisService.exists("DYaccessToken")){
+            //验证token是否过期
+            long dYaccessToken = redisService.getExpireTime("DYaccessToken");
+            if(dYaccessToken<=0){ //tonken过期
+                //判断refreshToken是否过期
+                long DyrefreshToken = redisService.getExpireTime("DyrefreshToken");
+                if(DyrefreshToken>=0){ //refreshToken
+                    //根据refreshToken刷新token,重新缓存token
+                    String refreshToken=redisService.get("DyrefreshToken").toString();
+                    String accessToken = refreshAccessToken(refreshToken);
+                    redisService.set("DYaccessToken",accessToken , 60L * 60 * 24 * 15);
+                   boolean flag= redisService.exists("DYaccessToken");
+                    return  ResponseJson.success(true);
+                }else{ //根据refreshToken刷新refreshToken(总共可以刷新3次,次数完后需重新扫码授权)
+                    String refreshToken=redisService.get("DyrefreshToken").toString();
+                    String newRefreshToken = resetRefreshAccessToken(refreshToken);
+                    if(StringUtils.isNotEmpty(newRefreshToken)){
+                        String accessToken = refreshAccessToken(newRefreshToken);
+                        redisService.set("DYaccessToken",accessToken,60L * 60 * 24 * 15);
+                        return  ResponseJson.success(true);
+                    }
+                }
+            }else {
+              return  ResponseJson.success(true);
+            }
+//        }
+//        String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
+//        String responestype = "code";//写死为'code'即可
+//        String scope = "video.data,video.list,trial.whitelist,data.external.item";//应用授权作用域,多个授权作用域以英文逗号(,)分隔
+//        String redirectUrl = "https://www.caimei365.com";//回调地址,应用中配置
+//        String state = "false";//用于保持请求和回调的状态
+//        String code = "https://open.douyin.com/platform/oauth/connect/?client_key=" + clintKey
+//                + "&response_type=" + responestype + "&scope=" + scope + "&redirect_uri=" + redirectUrl + "&state=" + state;
+//        response.sendRedirect(code);
+        return ResponseJson.success(false);
+    }
+
+    /**
+     * 根据用户的code值获取AcessToken
+     * ccode 用户授权登录code
+     **/
+    @Override
+    public ResponseJson getDouYingAcessToken(String code) throws IOException {
+        String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
+        String clintSecret = "1dd7446d29e16738787447b771ced2df";//应用唯一标识对应的密钥
+        String grantType = "authorization_code";//固定值
+        String requestUrl = "https://open.douyin.com/oauth/access_token/";//请求地址
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        //创建httppost对象
+        HttpPost hp = new HttpPost(requestUrl);
+        hp.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
+//        hp.setHeader("Content-Type","application/x-www-form-urlencoded");
+        //拼接请求参数
+        List<NameValuePair> list = new ArrayList();
+        list.add(new BasicNameValuePair("client_key", clintKey));
+        list.add(new BasicNameValuePair("client_secret", clintSecret));
+        list.add(new BasicNameValuePair("code", code));
+        list.add(new BasicNameValuePair("grant_type", grantType));
+        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
+        hp.setEntity(entity);
+        //发送请求
+        CloseableHttpResponse execute = closeableHttpClient.execute(hp);
+        HttpEntity he = execute.getEntity();
+        String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
+        //获取access_token,open_id(用于获取视频数据),refresh_token(刷新token)
+        JSONObject jsonObject =JSONObject.parseObject(result);
+        String data = jsonObject.getString("data");
+        JSONObject params =JSONObject.parseObject(data);
+        String accessToken = params.getString("access_token");
+        String openId = params.getString("open_id");
+        String refreshToken = params.getString("refresh_token");
+        //用redis缓存access_token,refresh_token
+        redisService.set("DYaccessToken",accessToken , 60L);// * 60 * 24 * 15
+        redisService.set("DyrefreshToken",refreshToken,60l*2);
+        redisService.set("DyopenId",openId,60L * 60 * 24 * 30);
+        EntityUtils.consume(he);
+        String DYaccessToken=redisService.get("DYaccessToken").toString();
+        String DyrefreshToken=redisService.get("DyrefreshToken").toString();
+        String DyopenId=redisService.get("DyopenId").toString();
+        if (StringUtils.isNotEmpty(DYaccessToken)&&StringUtils.isNotEmpty(DyrefreshToken)&&StringUtils.isNotEmpty(DyopenId)){
+            return ResponseJson.success();
+        }else {
+            return ResponseJson.success("tonken缓存失败",null);
+        }
+    }
+    /**
+     * 刷新tonken
+     * @param refreshToken
+     */
+    public String  refreshAccessToken(String refreshToken){
+        String requestUrl="https://open.douyin.com/oauth/refresh_token/";
+        String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
+        String grantType = "refresh_token";//固定值
+        String accessToken=null;
+        //创建httppost对象
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        HttpPost hp = new HttpPost(requestUrl);
+        hp.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
+//        hp.setHeader("Content-Type","application/x-www-form-urlencoded");
+        //拼接请求参数
+        List<NameValuePair> list = new ArrayList();
+        list.add(new BasicNameValuePair("client_key", clintKey));
+        list.add(new BasicNameValuePair("grant_type", grantType));
+        list.add(new BasicNameValuePair("refresh_token", refreshToken));
+        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
+        hp.setEntity(entity);
+        try {
+            CloseableHttpResponse execute = closeableHttpClient.execute(hp);
+            HttpEntity he = execute.getEntity();
+            String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
+            JSONObject params=JSONObject.parseObject(result);
+            String data=params.getString("data");
+            JSONObject datalist=JSONObject.parseObject(data);
+            accessToken=datalist.getString("access_token");
+            EntityUtils.consume(he);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        hp.setEntity(entity);
+        return accessToken;
+    }
+
+    /**
+     * 刷新refreshAccessToken
+     * @param refreshToken
+     */
+    public String  resetRefreshAccessToken(String refreshToken){
+        String requestUrl="https://open.douyin.com/oauth/renew_refresh_token/";
+        String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
+        String renewRefreshAccessToken=null;
+        //创建httppost对象
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        HttpPost hp = new HttpPost(requestUrl);
+        List<NameValuePair> list = new ArrayList();
+        list.add(new BasicNameValuePair("client_key", clintKey));
+        list.add(new BasicNameValuePair("refresh_token", refreshToken));
+        list.add(new BasicNameValuePair("Content-Type", "multipart/form-data"));
+        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
+        hp.setEntity(entity);
+        try {
+            CloseableHttpResponse execute = closeableHttpClient.execute(hp);
+            HttpEntity he = execute.getEntity();
+            String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
+            JSONObject jsonObject=JSONObject.parseObject(result);
+            String data = jsonObject.getString("data");
+            JSONObject params=JSONObject.parseObject(data);
+            renewRefreshAccessToken = params.getString("refresh_token");
+            EntityUtils.consume(he);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        hp.setEntity(entity);
+        return renewRefreshAccessToken;
+    }
+    //----------------------------------------------------h5的方式上传视频------------------------------------------------
+    /**
+     * h5的方式上传视频
+     * @return
+     * @throws IOException
+     */
+    @Override
+    public ResponseJson getclientToken(String title,String videoPath) throws IOException {
+        //获取accessToken
+        String client_key = "awwwvh9tsnvo54w1";
+        String client_secret = "1dd7446d29e16738787447b771ced2df";
+        String grant_type = "client_credential";
+        String url = "https://open.douyin.com/oauth/client_token/?client_key=" + client_key
+                + "&client_secret=" + client_secret
+                + "&grant_type=" + grant_type;
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        //创建httppost对象
+        HttpPost hp = new HttpPost(url);
+        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+        builder.setCharset(Consts.UTF_8);
+        builder.setContentType(ContentType.MULTIPART_FORM_DATA);
+        //构建参数
+        HttpEntity entity = builder.build();
+        hp.setEntity(entity);
+        CloseableHttpResponse response = null;
+        String schema=null;
+        try {
+            response = closeableHttpClient.execute(hp);
+            HttpEntity he = response.getEntity();
+            String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
+            //把返回结果转json获取access_token
+            JSONObject jsonObject=JSONObject.parseObject(result);
+            String data=jsonObject.getString("data");
+            JSONObject params=JSONObject.parseObject(data);
+            String accessToken=params.getString("access_token");
+            System.out.println(result);
+            System.out.println(accessToken);
+//            String accessToken = result.substring(result.indexOf("access_token") + "access_token".length() + 3, result.indexOf(",") - 1);
+//            System.out.println("access_token----"+accessToken);
+            //根据accesstoken获取tiket
+             schema = getDouYingTicket(accessToken, title,videoPath);
+            EntityUtils.consume(he);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return ResponseJson.success(schema);
+    }
+
+    /**
+     * 根据token获取ticket
+     **/
+    @RequestMapping("/getDouYingTicket")
+    public String getDouYingTicket(String clientToken,String title,String videoPath) throws IOException {
+        //时间戳
+        long l = System.currentTimeMillis();
+        String timestamp = String.valueOf(l);
+        //随机数
+        String noncestr = randomGen(16);
+        String uri = "https://open.douyin.com/open/getticket/";
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        HttpGet httpGet = new HttpGet(uri);
+        httpGet.setHeader("access-token", clientToken);
+        httpGet.setHeader("Content-Type","application/json");
+        CloseableHttpResponse response = null;
+        String schema=null;
+        try {
+            response = closeableHttpClient.execute(httpGet);
+            HttpEntity he = response.getEntity();
+            String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
+            System.out.println(result);
+            //获取ticket
+            JSONObject jsonObject=JSONObject.parseObject(result);
+            String data = jsonObject.getString("data");
+            JSONObject params=JSONObject.parseObject(data);
+            String ticket = params.getString("ticket");
+            System.out.println("ticket--"+ticket);
+            //getDouYingshareId
+            String shareId = getDouYingshareId(clientToken);
+            //获取签名 并且用md5加密
+            String signature = signatureAlgorithm(ticket, timestamp,noncestr);
+            //获取schema(返回前端用于生成二维码发布视频)
+             schema = appendSchema(signature, shareId, timestamp,noncestr, title, videoPath);
+            System.out.println("schema--:"+schema);
+            EntityUtils.consume(he);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return schema;
+    }
+
+    /**
+     * 获取签名 并且用md5加密
+     * ticket
+     **/
+    @RequestMapping("/signatureAlgorithm")
+    public String signatureAlgorithm(String ticket, String timestamp,String noncestr) {
+        TreeMap<String, String> treeMap = new TreeMap<>();
+        treeMap.put("nonce_str", noncestr);
+        treeMap.put("ticket", ticket);
+        treeMap.put("timestamp", timestamp);
+
+        StringBuffer stringBuffer = new StringBuffer();
+        Iterator<Map.Entry<String, String>> it = treeMap.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry<String, String> entry = it.next();
+            stringBuffer.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
+        }
+        String result = stringBuffer.substring(0, stringBuffer.length() - 1);
+        System.out.println(result);
+        //进行md5签名
+        String signature = Md5Util.md5(result).toLowerCase();
+        System.out.println(signature);
+        return signature;
+    }
+
+    /**
+     * Schema 生成
+     **/
+    public String appendSchema(String signature, String shareId, String timestamp,String noncestr,String title,String videoPath) {
+        URIBuilder uri = null;
+        String schema = null;
+        try {
+            uri = new URIBuilder("snssdk1128://openplatform/share");
+            uri.addParameter("share_type", "h5");//固定h5
+            uri.addParameter("client_key", "awwwvh9tsnvo54w1");//应用唯一标识
+            uri.addParameter("nonce_str", noncestr);//随机数(必须和签名时的nonce_str一致)
+            uri.addParameter("timestamp", timestamp);//时间戳(必须和签名时的timestamp一致)
+            uri.addParameter("signature", signature);//签名
+            uri.addParameter("state", shareId);//通过方法获取(基于webhook,获取视频发布回调信息,不传则收不到回调信息)
+//https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4
+            //视频地址(必须为网络地址,本地地址无法发布)单视频上传
+            uri.addParameter("video_path",videoPath);//"https://caimei-oss.oss-cn-shenzhen.aliyuncs.com/beta/authFile/5c7bfb6e-9919-48b1-a905-88a888f22a11.mp4");//https://caimei-oss.oss-cn-shenzhen.aliyuncs.com/beta/authFile/5c7bfb6e-9919-48b1-a905-88a888f22a11.mp4
+            uri.addParameter("share_to_publish", "1");//为1则直接发布视频至抖音
+            uri.addParameter("title",title);//"给大佐都整emo了");//视频标题
+            schema = uri.toString();
+        } catch (URISyntaxException e) {
+            e.printStackTrace();
+        }
+        return schema;
+    }
+
+    /**
+     * 获取shareId  用于生成schema
+     **/
+    @RequestMapping("/getDouYingshareId")
+    public String getDouYingshareId(String clientToken) throws IOException {
+        String uri = "https://open.douyin.com/share-id/?need_callback=true&default_hashtag=hashtag";
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        HttpGet httpGet = new HttpGet(uri);
+        httpGet.setHeader("access-token", clientToken);
+        CloseableHttpResponse response = null;
+        String shareId = "";
+        try {
+            response = closeableHttpClient.execute(httpGet);
+            HttpEntity he = response.getEntity();
+            String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
+            JSONObject jsonObject=JSONObject.parseObject(result);
+            String data = jsonObject.getString("data");
+            JSONObject params=JSONObject.parseObject(data);
+            shareId = params.getString("share_id");
+            System.out.println(result);
+            System.out.println(shareId);
+            EntityUtils.consume(he);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return shareId;
+    }
+
+    /**
+     * 获取已发布视频列表
+     * @param openId 用户唯一标志
+     * @param cursor 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
+     * @param count  每页数量 10
+     */
+    public void getVideoList(String openId,Integer cursor,Integer count,String accessToken){
+        String requestUrl="https://open.douyin.com/video/list/?open_id="+openId+"&cursor="+cursor+"&count="+count;
+        //创建httppost对象
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        HttpGet hg = new HttpGet(requestUrl);
+        hg.setHeader("Content-Type","application/json");
+        hg.addHeader("access-token",accessToken);
+        try {
+            CloseableHttpResponse execute = closeableHttpClient.execute(hg);
+            HttpEntity entity = execute.getEntity();
+            String result=EntityUtils.toString(entity,StandardCharsets.UTF_8);
+            System.out.println(result);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            String data = jsonObject.getString("data");
+            JSONObject paramslist = JSONObject.parseObject(data);
+            String itemIdlist = paramslist.getString("list");
+            System.out.println("list----"+itemIdlist);
+            JSONArray params = JSONArray.parseArray(itemIdlist);
+            String itemId = params.getJSONObject(0).get("item_id").toString();
+            System.out.println("item_id-----"+itemId);
+            //根据itemid获取视频的数据(点赞,播放,评论量)
+            EntityUtils.consume(entity);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /**
+     * 生成随机数
+     *
+     * @param place
+     * @return
+     */
+    public String randomGen(int place) {
+        String base = "wqetryuioplkjhgfdsazxcvbmnABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+        StringBuffer sb = new StringBuffer();
+        Random rd = new Random();
+        for (int i = 0; i < place; i++) {
+            sb.append(base.charAt(rd.nextInt(base.length())));
+        }
+        return sb.toString();
+    }
 }

+ 1 - 0
src/main/java/com/caimei/utils/SmsUtils.java

@@ -42,6 +42,7 @@ public class SmsUtils {
             passList.add("18476937515");
             passList.add("15917362709");
             passList.add("15872950940");
+            passList.add("18229303772");
             if ("prod".equals(active) || passList.contains(mobile)) {
                 if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
                     String regex = "^(1[3-9]\\d{9}$)";

+ 0 - 1
src/main/resources/mapper/SystemMapper.xml

@@ -267,7 +267,6 @@
           and base_flag = 0
           and status = 0
           and m.parent_id = 0
-          and r.authUserId is null
     </select>
     <select id="getVipRoleIdList" resultType="java.lang.Integer">
         select role_id from auth_role_user where user_id = #{authUserId}