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.
273 lines
7.7 KiB
273 lines
7.7 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.wx.config.WeChatConfig;
|
|
import com.ynxbd.wx.utils.DesEncryptHelper;
|
|
import com.ynxbd.wx.wxfactory.ReqParamHelper;
|
|
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.Base64;
|
|
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);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println(DesEncryptHelper.deCode("98EBC51EB92C6BC416BE23AE0622CC7445CCB4559637127984C5759A422DC4B81251FC4C8B32A9DB9743601A4C4D66A31FA5186B9BF10CBCF7ACB00A82EBC37122FD51700AC9D16D596D147FFC4D4973792E04B406288B88D08C6ACE9654DA3801B31D2F6B996D3572A3BA1E8124A5CE43394DF49E1B5F0DC7793566C06524A854161F38FF064F3B"));
|
|
}
|
|
|
|
@Action("getWxJsapiTicket")
|
|
public Result getWxJsapiTicket() {
|
|
String ticket = WxCacheHelper.getJsapiTicket();
|
|
if (ticket == null) {
|
|
return Result.error();
|
|
}
|
|
Map<String, Object> data = new HashMap<>();
|
|
data.put("ticket", ticket);
|
|
data.put("appId", WeChatConfig.APP_ID);
|
|
return Result.success(data);
|
|
}
|
|
|
|
/**
|
|
* 获取系统公钥
|
|
*
|
|
* @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);
|
|
}
|
|
|
|
@Action("getEnPatientId")
|
|
public Result getEnPatientId(String patientId) {
|
|
if (patientId == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
patientId = ReqParamHelper.encode(patientId);
|
|
for (int i = 0; i < 3; i++) {
|
|
patientId = Base64.getEncoder().encodeToString(patientId.getBytes());
|
|
}
|
|
return Result.success(patientId);
|
|
}
|
|
|
|
/**
|
|
* 清除患者缓存
|
|
*
|
|
* @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:发送失败");
|
|
}
|
|
|
|
}
|
|
|