LAPTOP-KB9HII50\70708 преди 3 години
родител
ревизия
6a3efa3663

+ 8 - 0
svr/svr-cloud-care/pom.xml

@ -270,6 +270,14 @@
            <artifactId>artemis-http-client</artifactId>
            <version>1.1.3</version>
        </dependency>
        <!--钉钉sdk-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>zwdd-sdk-java</artifactId>
            <version>1.2.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/lib/zwdd-sdk-java-1.2.0.jar</systemPath>
        </dependency>
    </dependencies>
    <build>

+ 31 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/doctor/DoctorEndpoint.java

@ -7,8 +7,10 @@ import com.yihu.jw.care.service.consult.ConsultTeamService;
import com.yihu.jw.care.service.doctor.CareDoctorService;
import com.yihu.jw.care.service.doctor.DoctorServicePermissionsService;
import com.yihu.jw.care.service.sign.CapacityAssessmentRecordService;
import com.yihu.jw.care.util.DingdingUtil;
import com.yihu.jw.care.util.EntranceUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
@ -47,7 +49,36 @@ public class DoctorEndpoint extends EnvelopRestEndpoint {
    private DoctorServicePermissionsService doctorServicePermissionsService;
    @Autowired
    private PermissionService permissionService;
    @Autowired
    private DingdingUtil dingdingUtil;
    @GetMapping(value = "dingtalk_app_user")
    @ApiOperation(value = "钉钉授权code获取用户信息")
    public Envelop dingtalk_app_user(@ApiParam(name = "authCode", value = "钉钉授权code", required = true)
                                     @RequestParam(value = "authCode",required = true) String authCode){
        try {
            JSONObject jsonObject = dingdingUtil.dingtalk_app_user(authCode);
            if(jsonObject.getBoolean("success")){
                JSONObject content = jsonObject.getJSONObject("content");
                if(content.getBoolean("success")){
                    long accountId = content.getJSONObject("data").getLong("accountId");
                    BaseDoctorDO doctorDO = doctorDao.findByYktDoctorId(accountId+"");
                    if(doctorDO == null){
                        return Envelop.getError("暂无该账号,请联系云照护工作人员配置");
                    }else{
                        return success(doctorDO.getMobile());
                    }
                }else{
                    return Envelop.getError(content.getString("responseMessage"));
                }
            }else {
                return Envelop.getError("获取失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return failedException2(e);
        }
    }
    @PostMapping(value = "updOnline")
    @ApiOperation(value = "更新在线状态")

+ 156 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/DingdingUtil.java

@ -0,0 +1,156 @@
package com.yihu.jw.care.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.GetClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import com.yihu.jw.utils.ByteToInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
 * 阿里巴巴钉钉工具类
 * Created by yeshijie on 2022/3/23.
 */
@Component
public class DingdingUtil {
    private static final Logger logger = LoggerFactory.getLogger(DingdingUtil.class);
    //测试
    private static final String AppKey = "ceshiyzh-jtP6zf3cfZEqs8UmmYNra";
    private static final String AppSecret = "NbbH9viHPDNTPTuQPz2Y0Y06F88krYWTTPLv0h01";
    //正式
//    private static final String AppKey = "zhyzh-r085NCVALJYmgcDc7oBVFRZj";
//    private static final String AppSecret = "fH8ZVDGAmJaeF7ujwAZgCi40w0U3im9J801vBaSF";
    private static final String DomainName = "openplatform.dg-work.cn";
    private static final String tenantId = "50495309";
    private static final String gettokenApi = "/gettoken.json";
    private static final String dingtalk_app_user = "/rpc/oauth2/dingtalk_app_user.json";
    private static final String get_by_mobiles = "/mozi/employee/get_by_mobiles";
    private static final String getuserinfo_bycode = "/rpc/oauth2/getuserinfo_bycode.json";
    //executableClient要单例,并且使用前要初始化,只需要初始化一次
    private static ExecutableClient executableClient = null;
    @PostConstruct
    public void clientInit(){
        if(executableClient == null){
            synchronized(ExecutableClient.class){
                if(executableClient == null){
                    executableClient = ExecutableClient.getInstance();
                    executableClient.setAccessKey(AppKey);
                    executableClient.setSecretKey(AppSecret);
                    executableClient.setDomainName(DomainName);
                    executableClient.setProtocal("https");
                    executableClient.init();
                }
            }
        }
    }
    /**
     * 获取AccessToken
     * @return
     */
    public String getAccessToken(){
        GetClient getClient = executableClient.newGetClient(gettokenApi);
        //设置参数
        getClient.addParameter("appkey", AppKey);
        getClient.addParameter("appsecret", AppSecret);
        //调用API
        String apiResult = getClient.get();
        logger.info(apiResult);
        //{"success":true,"content":{"data":{"expiresIn":7200,"accessToken":"app_4197121c698246cea9ec660902324edd"},"success":true,"requestId":"276077ca16480212814976877e76c6","responseMessage":"OK","responseCode":"0","bizErrorCode":"0"},"bizErrorCode":"0"}
        JSONObject jsonObject = JSON.parseObject(apiResult);
        if(jsonObject.getBoolean("success")){
            JSONObject content = jsonObject.getJSONObject("content");
            if(content.getBoolean("success")){
                return content.getJSONObject("data").getString("accessToken");
            }
        }
        return null;
    }
    /**
     * 获取用户信息
     * @return
     */
    public JSONObject dingtalk_app_user(String authCode){
        //调用API
        PostClient postClient = executableClient.newPostClient(dingtalk_app_user);
        //设置参数
        postClient.addParameter("access_token", getAccessToken());
        postClient.addParameter("auth_code", "11");
        //Call API
        String apiResult = postClient.post();
        logger.info(apiResult);
        //{"success":true,"content":{"success":false,"responseMessage":"code失效或不存在","responseCode":"240111","bizErrorCode":"MBS-B001-02-16-240111"}}
        return JSON.parseObject(apiResult);
    }
    /**
     * 根据手机号获取员工账户id
     * @param mobiles
     * @return
     */
    public static JSONArray get_by_mobiles(String mobiles){
        //调用API
        PostClient postClient = executableClient.newPostClient(get_by_mobiles);
        //设置参数
        postClient.addParameter("areaCode", "86");
        //手机号码列表,逗号分隔,最多50个
        postClient.addParameter("mobiles", mobiles);
        postClient.addParameter("tenantId", tenantId);
        postClient.addParameter("namespace", "local");
        //Call API
        String apiResult = postClient.post();
        logger.info(apiResult);
        //{"success":true,"content":{"data":[{"accountId":821685,"mobile":"15859634562","employeeCode":"GE_f27a7231e19f4b31b8f11d2859d1be07","status":0},{"accountId":821606,"mobile":"13559485270","employeeCode":"GE_10933a0f8bc949149143163cba5bb81f","status":0}],"success":true,"requestId":"2760828316480239373806874ed97b","responseMessage":"OK","responseCode":"0","bizErrorCode":"0"},"bizErrorCode":"0"}
        JSONObject jsonObject = JSON.parseObject(apiResult);
        if(jsonObject.getBoolean("success")){
            JSONObject content = jsonObject.getJSONObject("content");
            if(content.getBoolean("success")){
                return content.getJSONArray("data");
            }
        }
        return null;
    }
    public String getuserinfo_bycode(String code){
        //调用API
        PostClient postClient = executableClient.newPostClient(getuserinfo_bycode);
        //设置参数
        postClient.addParameter("access_token", getAccessToken());
        postClient.addParameter("code", code);
        //Call API
        String apiResult = postClient.post();
        logger.info(apiResult);
//        JSONObject jsonObject = JSON.parseObject(apiResult);
//        if(jsonObject.getBoolean("success")){
//            JSONObject content = jsonObject.getJSONObject("content");
//            if(content.getBoolean("success")){
//                return content.getJSONObject("data").getString("accessToken");
//            }
//        }
        return null;
    }
//    public static void main(String[] args) {
//        String mobiles = "13559485270,15859634562";
//        System.out.println(get_by_mobiles(mobiles));
//        getuserinfo_bycode("f826c1a762a54ce6abb01c74dcc3ec000c89b501");
//
//        dingtalk_app_user("f826c1a762a54ce6abb01c74dcc3ec000c89b501");
//    }
}

BIN
svr/svr-cloud-care/src/main/lib/zwdd-sdk-java-1.2.0.jar