You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							254 lines
						
					
					
						
							6.8 KiB
						
					
					
				
			
		
		
	
	
							254 lines
						
					
					
						
							6.8 KiB
						
					
					
				package com.ynxbd.common.action;
 | 
						|
 | 
						|
import com.ynxbd.common.action.base.BaseAction;
 | 
						|
import com.ynxbd.common.bean.Patient;
 | 
						|
import com.ynxbd.common.bean.User;
 | 
						|
import com.ynxbd.common.bean.sms.SmsTemplate;
 | 
						|
import com.ynxbd.common.helper.common.*;
 | 
						|
import com.ynxbd.common.result.Result;
 | 
						|
import com.ynxbd.common.result.ResultEnum;
 | 
						|
import com.ynxbd.common.result.ServiceException;
 | 
						|
import com.ynxbd.wx.config.WeChatConfig;
 | 
						|
import com.ynxbd.wx.utils.DesEncryptHelper;
 | 
						|
import com.ynxbd.wx.wxfactory.WxAuthHelper;
 | 
						|
import com.ynxbd.wx.wxfactory.WxCacheHelper;
 | 
						|
import com.ynxbd.wx.wxfactory.bean.AccessToken;
 | 
						|
import lombok.extern.slf4j.Slf4j;
 | 
						|
import org.apache.commons.lang3.ObjectUtils;
 | 
						|
import org.apache.struts2.convention.annotation.Action;
 | 
						|
import org.apache.struts2.convention.annotation.Namespace;
 | 
						|
 | 
						|
import java.util.HashMap;
 | 
						|
import java.util.Map;
 | 
						|
 | 
						|
/**
 | 
						|
 * @Author wsq
 | 
						|
 * @Date 2021/1/7 17:26
 | 
						|
 * @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
 | 
						|
 */
 | 
						|
@Slf4j
 | 
						|
@Namespace("/api")
 | 
						|
public class ApiAction extends BaseAction {
 | 
						|
 | 
						|
    /**
 | 
						|
     * 获取系统accessToken(需解密)
 | 
						|
     *
 | 
						|
     * @return 公钥
 | 
						|
     */
 | 
						|
    @Action("getWxAccessToken")
 | 
						|
    public Result getWxAccessToken() {
 | 
						|
        AccessToken resp = WxCacheHelper.getWxAccessToken();
 | 
						|
        if (resp == null) {
 | 
						|
            return Result.error();
 | 
						|
        }
 | 
						|
 | 
						|
        String accessToken = resp.getAccessToken();
 | 
						|
        if (accessToken == null) {
 | 
						|
            return Result.error();
 | 
						|
        }
 | 
						|
        log.warn(accessToken);
 | 
						|
 | 
						|
        accessToken = DesEncryptHelper.enCode(accessToken);
 | 
						|
        if (accessToken == null) {
 | 
						|
            return Result.error();
 | 
						|
        }
 | 
						|
 | 
						|
        resp.setAccessToken(accessToken);
 | 
						|
        return Result.success(resp);
 | 
						|
    }
 | 
						|
 | 
						|
    @Action("getWxJsapiTicket")
 | 
						|
    public Result getWxJsapiTicket() {
 | 
						|
        String ticket = WxCacheHelper.getJsapiTicket();
 | 
						|
        if (ticket ==null)
 | 
						|
            return Result.error();
 | 
						|
        return Result.success(ticket);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 获取系统公钥
 | 
						|
     *
 | 
						|
     * @return 公钥
 | 
						|
     */
 | 
						|
    @Action("deBase")
 | 
						|
    public Result deBase(String data) {
 | 
						|
        return Result.success(Base64Helper.decode(data));
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     //     * 获取系统公钥
 | 
						|
     //     *
 | 
						|
     //     * @return 公钥
 | 
						|
     //     */
 | 
						|
//    @Action("pdf")
 | 
						|
//    public Result pdf(String data) {
 | 
						|
//        try {
 | 
						|
//            System.out.println(data);
 | 
						|
//            BASE64Decoder decoder = new BASE64Decoder();
 | 
						|
//            byte[] decodedBytes = decoder.decodeBuffer(data);
 | 
						|
//
 | 
						|
//            File file = new File("C:\\Users\\Administrator\\Desktop\\test.pdf");;
 | 
						|
//            FileOutputStream fop = new FileOutputStream(file);
 | 
						|
//
 | 
						|
//            fop.write(decodedBytes);
 | 
						|
//            fop.flush();
 | 
						|
//            fop.close();
 | 
						|
//        } catch (Exception e) {
 | 
						|
//            e.printStackTrace();
 | 
						|
//        }
 | 
						|
//        return Result.success();
 | 
						|
//    }
 | 
						|
//
 | 
						|
//
 | 
						|
//    /**
 | 
						|
//     * 获取系统公钥
 | 
						|
//     *
 | 
						|
//     * @return 公钥
 | 
						|
//     */
 | 
						|
//    @Action("pImg")
 | 
						|
//    public Result pImg(String data) {
 | 
						|
//        String s = Base64Helper.pdfBaseToImgBase(data);
 | 
						|
//        return Result.success(s);
 | 
						|
//    }
 | 
						|
//
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * 获取系统公钥
 | 
						|
     *
 | 
						|
     * @return 公钥
 | 
						|
     */
 | 
						|
    @Action("getPublicKey")
 | 
						|
    public Result getPublicKey() {
 | 
						|
        return Result.success(RSAHelper.getPublicKey());
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 获取系统公钥
 | 
						|
     *
 | 
						|
     * @return 公钥
 | 
						|
     */
 | 
						|
    @Action("getWebUrl")
 | 
						|
    public Result getWebUrl() {
 | 
						|
        return Result.success(WeChatConfig.getWebUrl());
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 身份证识别
 | 
						|
     *
 | 
						|
     * @return 识别到的信息
 | 
						|
     */
 | 
						|
    @Action("idCard")
 | 
						|
    public Result idCard(String image) {
 | 
						|
        if (image == null) {
 | 
						|
            return Result.error("image为空");
 | 
						|
        }
 | 
						|
        Patient patient = IDNumberHelper.getCardInfo(image);
 | 
						|
 | 
						|
        log.info("身份证信息-{{}}", patient);
 | 
						|
 | 
						|
        return patient == null ? Result.error() : Result.success(patient);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 身份证识别
 | 
						|
     *
 | 
						|
     * @return 识别到的信息
 | 
						|
     */
 | 
						|
    @Action("getQrCodeBase")
 | 
						|
    public Result getQrCodeBase(Integer size, String content) {
 | 
						|
        if (content == null || size == null) {
 | 
						|
            return Result.error(ResultEnum.PARAM_IS_DEFECT);
 | 
						|
        }
 | 
						|
        String base = QRCodeHelper.encodeToBase64(content, size, size);
 | 
						|
        return Result.success(base);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 清除患者缓存
 | 
						|
     *
 | 
						|
     * @return 识别到的信息
 | 
						|
     */
 | 
						|
    @Action("clearPatientCache")
 | 
						|
    public Result clearPatientCache(String openid) {
 | 
						|
        if (ObjectUtils.isEmpty(openid)) {
 | 
						|
            return Result.error();
 | 
						|
        }
 | 
						|
        User cacheUser = WxCacheHelper.getCacheUser(openid);
 | 
						|
        if (cacheUser == null) {
 | 
						|
            return Result.error("没有缓存");
 | 
						|
        }
 | 
						|
        WxCacheHelper.getUserCache().remove(openid);
 | 
						|
        return Result.success();
 | 
						|
    }
 | 
						|
 | 
						|
    @Action("ip")
 | 
						|
    public Result ip() {
 | 
						|
        Map<String, String> map = new HashMap<>();
 | 
						|
        String inIp = HttpHelper.getInIP();
 | 
						|
        String outIP = HttpHelper.getOutIP();
 | 
						|
        map.put("内网IP", inIp);
 | 
						|
        map.put("外网IP", outIP);
 | 
						|
        return Result.success(map);
 | 
						|
    }
 | 
						|
 | 
						|
    @Action("version")
 | 
						|
    public Result version() {
 | 
						|
       return Result.success(VersionHelper.getAppVersion());
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * 第三方使用勿动!
 | 
						|
     */
 | 
						|
    @Action("smsHelp")
 | 
						|
    public String smsHelp() {
 | 
						|
        String phoneNo = getString("phoneno");
 | 
						|
        if (phoneNo == null) {
 | 
						|
            return respEnd("ERROR:电话号码无效");
 | 
						|
        }
 | 
						|
 | 
						|
        if (phoneNo.length() != 11) {
 | 
						|
            return respEnd("ERROR:电话号码长度异常");
 | 
						|
        }
 | 
						|
 | 
						|
        String code = getString("codeno");
 | 
						|
        if (code == null) {
 | 
						|
            return respEnd("ERROR:验证码无效");
 | 
						|
        }
 | 
						|
 | 
						|
        if (code.length() > 6 || code.length() < 4) {
 | 
						|
            return respEnd("ERROR:验证码长度异常");
 | 
						|
        }
 | 
						|
 | 
						|
        String callNo = getString("callno");
 | 
						|
 | 
						|
 | 
						|
        // 判断是否60s内重复请求
 | 
						|
        SmsTemplate sms = SmsHelper.isRepeat(phoneNo);
 | 
						|
        if (sms != null) {
 | 
						|
            return respEnd("REPEAT"); // 60s内重复请求
 | 
						|
        }
 | 
						|
 | 
						|
        boolean isFlag;
 | 
						|
        String template;
 | 
						|
        switch (callNo) {
 | 
						|
            case "dhzzyyy001": // 东软自助机
 | 
						|
                template = "SMS_173475681";
 | 
						|
                isFlag = SmsHelper.sendCode(template, phoneNo, code);
 | 
						|
 | 
						|
                break;
 | 
						|
 | 
						|
            default:
 | 
						|
                log.info("调用码无效");
 | 
						|
                return respEnd("ERROR:调用码无效");
 | 
						|
        }
 | 
						|
 | 
						|
        if (isFlag) {
 | 
						|
            return respEnd("SUCCESS"); // 成功
 | 
						|
        }
 | 
						|
        return respEnd("ERROR:发送失败");
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |