Merge remote-tracking branch 'origin/feature-20240104' into feature-20240104
commit
b8637a122d
@ -0,0 +1,30 @@
|
||||
package com.flossom.common.core.enums;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
* @author flossom
|
||||
*/
|
||||
public enum Status
|
||||
{
|
||||
OK("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
Status(String code, String info)
|
||||
{
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.flossom.miniProgram.Enums;
|
||||
|
||||
/**
|
||||
* 系统设置-key 枚举
|
||||
*/
|
||||
public enum SystemSettingKeyEnum {
|
||||
USER_AGREEMENT("USER_AGREEMENT", "用户协议"),
|
||||
PRIVACY_AGREEMENT("PRIVACY_AGREEMENT", "隐私协议"),
|
||||
INTEGRAL_RULE("INTEGRAL_RULE", "积分规则"),
|
||||
ABOUT_US("ABOUT_US", "关于我们");
|
||||
|
||||
private final String key;
|
||||
private final String remark;
|
||||
|
||||
SystemSettingKeyEnum(String key, String remark) {
|
||||
this.key = key;
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package com.flossom.miniProgram.controller;
|
||||
|
||||
import com.flossom.common.core.web.controller.BaseController;
|
||||
import com.flossom.common.core.web.domain.AjaxResult;
|
||||
import com.flossom.miniProgram.service.ISystemSettingService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 平台参数设置
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/setting")
|
||||
public class SystemSettingController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ISystemSettingService systemSettingService;
|
||||
|
||||
/**
|
||||
* 获取 用户协议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserAgreement")
|
||||
public AjaxResult getUserAgreement() {
|
||||
return AjaxResult.success(systemSettingService.getUserAgreement());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 隐私协议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getPrivacyAgreement")
|
||||
public AjaxResult getPrivacyAgreement() {
|
||||
return AjaxResult.success(systemSettingService.getPrivacyAgreement());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 积分规则
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getIntegralRule")
|
||||
public AjaxResult getIntegralRule() {
|
||||
return AjaxResult.success(systemSettingService.getIntegralRule());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 关于我们
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getAboutUs")
|
||||
public AjaxResult getAboutUs() {
|
||||
return AjaxResult.success(systemSettingService.getAboutUs());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.flossom.miniProgram.controller;
|
||||
|
||||
import com.flossom.common.core.web.controller.BaseController;
|
||||
import com.flossom.common.core.web.domain.AjaxResult;
|
||||
import com.flossom.miniProgram.service.IWelcomeService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 首页视频、欢迎页、登录页
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/welcome")
|
||||
public class WelcomeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IWelcomeService welcomeService;
|
||||
|
||||
/**
|
||||
* 获取首页视频
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/obtain/firstPageVideo")
|
||||
public AjaxResult obtainFirstPageVideo() {
|
||||
return AjaxResult.success(welcomeService.obtainFirstPageVideo());
|
||||
}
|
||||
|
||||
@GetMapping("/obtain/firstPageIntroduction")
|
||||
public AjaxResult obtainFirstPageIntroduction() {
|
||||
return AjaxResult.success(welcomeService.obtainFirstPageIntroduction());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
package com.flossom.miniProgram.domain;
|
||||
|
||||
import com.flossom.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class WxUserMember extends BaseEntity {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String headimg;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 积分 decimal(10,2)
|
||||
*/
|
||||
private Double credit;
|
||||
|
||||
/**
|
||||
* openid
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* DEFAULT NULL
|
||||
*/
|
||||
private String unionid;
|
||||
|
||||
/**
|
||||
* 微信号
|
||||
*/
|
||||
private String wechat;
|
||||
|
||||
/**
|
||||
* 应该是邀请码来的
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 默认普通会员
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 个人二维码
|
||||
*/
|
||||
private String userQr;// 个人二维码
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
private String area;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 1可以,2不可以
|
||||
*/
|
||||
private Integer clock;
|
||||
|
||||
/**
|
||||
* DEFAULT '1' ,'1可以2不可以',
|
||||
*/
|
||||
private Integer activity;
|
||||
|
||||
/**
|
||||
* DEFAULT '1' COMMENT '1 未对接到中控 2已经对接 3对接失败'
|
||||
*/
|
||||
private Integer isAbutment;
|
||||
|
||||
/**
|
||||
* decimal(15,2) DEFAULT '0.00'
|
||||
*/
|
||||
private Double collagenDay;
|
||||
|
||||
/**
|
||||
* decimal(15,2) DEFAULT '0.00'
|
||||
*/
|
||||
private Double collagenMount;
|
||||
|
||||
/**
|
||||
* 登陆时间
|
||||
*/
|
||||
private Date loginTime;
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package com.flossom.miniProgram.domain.vo;
|
||||
|
||||
/**
|
||||
* 登录响应结果
|
||||
*/
|
||||
public class WxCode2SessionRet {
|
||||
private String openid;
|
||||
private String session_key;
|
||||
private String unionid;
|
||||
private Integer errcode;
|
||||
private String errmsg;
|
||||
|
||||
public WxCode2SessionRet() {
|
||||
}
|
||||
|
||||
public WxCode2SessionRet(String openid, String session_key, String unionid, Integer errcode, String errmsg) {
|
||||
this.openid = openid;
|
||||
this.session_key = session_key;
|
||||
this.unionid = unionid;
|
||||
this.errcode = errcode;
|
||||
this.errmsg = errmsg;
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public String getSession_key() {
|
||||
return session_key;
|
||||
}
|
||||
|
||||
public void setSession_key(String session_key) {
|
||||
this.session_key = session_key;
|
||||
}
|
||||
|
||||
public String getUnionid() {
|
||||
return unionid;
|
||||
}
|
||||
|
||||
public void setUnionid(String unionid) {
|
||||
this.unionid = unionid;
|
||||
}
|
||||
|
||||
public Integer getErrcode() {
|
||||
return errcode;
|
||||
}
|
||||
|
||||
public void setErrcode(Integer errcode) {
|
||||
this.errcode = errcode;
|
||||
}
|
||||
|
||||
public String getErrmsg() {
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
public void setErrmsg(String errmsg) {
|
||||
this.errmsg = errmsg;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.flossom.miniProgram.mapper;
|
||||
|
||||
import com.flossom.miniProgram.Enums.SystemSettingKeyEnum;
|
||||
import com.flossom.miniProgram.domain.WxSystemSetting;
|
||||
|
||||
public interface SystemSettingMapper {
|
||||
|
||||
WxSystemSetting getSystemSettingByKey(String systemSetKey);
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.flossom.miniProgram.service;
|
||||
|
||||
import com.flossom.miniProgram.domain.WxSystemSetting;
|
||||
|
||||
public interface ISystemSettingService {
|
||||
|
||||
WxSystemSetting getUserAgreement();
|
||||
|
||||
WxSystemSetting getPrivacyAgreement();
|
||||
|
||||
WxSystemSetting getIntegralRule();
|
||||
|
||||
WxSystemSetting getAboutUs();
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.flossom.miniProgram.service;
|
||||
|
||||
|
||||
import com.flossom.miniProgram.domain.WxWelcomeSetting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IWelcomeService {
|
||||
|
||||
public WxWelcomeSetting obtainFirstPageVideo();
|
||||
|
||||
|
||||
public List<WxWelcomeSetting> obtainFirstPageIntroduction();
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package com.flossom.miniProgram.service.impl;
|
||||
|
||||
import com.flossom.miniProgram.Enums.SystemSettingKeyEnum;
|
||||
import com.flossom.miniProgram.domain.WxSystemSetting;
|
||||
import com.flossom.miniProgram.mapper.SystemSettingMapper;
|
||||
import com.flossom.miniProgram.service.ISystemSettingService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SystemSettingServiceImpl implements ISystemSettingService {
|
||||
|
||||
@Autowired
|
||||
private SystemSettingMapper systemSettingMapper;
|
||||
|
||||
/**
|
||||
* 获取 用户协议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public WxSystemSetting getUserAgreement() {
|
||||
return systemSettingMapper.getSystemSettingByKey(SystemSettingKeyEnum.USER_AGREEMENT.getKey());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 隐私协议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public WxSystemSetting getPrivacyAgreement() {
|
||||
return systemSettingMapper.getSystemSettingByKey(SystemSettingKeyEnum.PRIVACY_AGREEMENT.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 积分规则
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public WxSystemSetting getIntegralRule() {
|
||||
return systemSettingMapper.getSystemSettingByKey(SystemSettingKeyEnum.INTEGRAL_RULE.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 关于我们
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public WxSystemSetting getAboutUs() {
|
||||
return systemSettingMapper.getSystemSettingByKey(SystemSettingKeyEnum.ABOUT_US.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.flossom.miniProgram.service.impl;
|
||||
|
||||
import com.flossom.miniProgram.Enums.FirstPageTypeEnum;
|
||||
import com.flossom.miniProgram.domain.WxWelcomeSetting;
|
||||
import com.flossom.miniProgram.mapper.WelcomeMapper;
|
||||
import com.flossom.miniProgram.service.IWelcomeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class WelcomeServiceImpl implements IWelcomeService {
|
||||
|
||||
@Autowired
|
||||
private WelcomeMapper welcomeMapper;
|
||||
|
||||
@Override
|
||||
public WxWelcomeSetting obtainFirstPageVideo() {
|
||||
List<WxWelcomeSetting> settings = welcomeMapper.obtainWxWlComeSetting(FirstPageTypeEnum.First_PAGE_VIDEO.getType());
|
||||
if (settings == null || settings.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
// 首页视频只有一个,配置多个只返回第一个
|
||||
return settings.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxWelcomeSetting> obtainFirstPageIntroduction() {
|
||||
List<WxWelcomeSetting> settings = welcomeMapper.obtainWxWlComeSetting(FirstPageTypeEnum.FIRST_WELCOME_IMAGE.getType());
|
||||
if (settings == null || settings.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.flossom.miniProgram.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ByteGroup {
|
||||
ArrayList<Byte> byteContainer = new ArrayList<Byte>();
|
||||
|
||||
public byte[] toBytes() {
|
||||
byte[] bytes = new byte[byteContainer.size()];
|
||||
for (int i = 0; i < byteContainer.size(); i++) {
|
||||
bytes[i] = byteContainer.get(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public ByteGroup addBytes(byte[] bytes) {
|
||||
for (byte b : bytes) {
|
||||
byteContainer.add(b);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return byteContainer.size();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,334 @@
|
||||
package com.flossom.miniProgram.utils;
|
||||
|
||||
|
||||
import com.flossom.common.core.utils.StringUtils;
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.config.RequestConfig.Builder;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
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.conn.ConnectTimeoutException;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.SSLContextBuilder;
|
||||
import org.apache.http.conn.ssl.TrustStrategy;
|
||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class HttpClientUtils {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MiniProgramUtils.class);
|
||||
|
||||
public static final int connTimeout = 10000;
|
||||
public static final int readTimeout = 10000;
|
||||
public static final String charset = "UTF-8";
|
||||
private static HttpClient client = null;
|
||||
|
||||
static {
|
||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||
cm.setMaxTotal(128);
|
||||
cm.setDefaultMaxPerRoute(128);
|
||||
client = HttpClients.custom().setConnectionManager(cm).build();
|
||||
}
|
||||
|
||||
public static String postParameters(String url, String parameterStr) throws ConnectTimeoutException, SocketTimeoutException, Exception {
|
||||
return post(url, parameterStr, "application/x-www-form-urlencoded", charset, connTimeout, readTimeout);
|
||||
}
|
||||
|
||||
public static String postParameters(String url, String parameterStr, String charset, Integer connTimeout, Integer readTimeout) throws ConnectTimeoutException, SocketTimeoutException, Exception {
|
||||
return post(url, parameterStr, "application/x-www-form-urlencoded", charset, connTimeout, readTimeout);
|
||||
}
|
||||
|
||||
public static String postParameters(String url, Map<String, String> params) throws ConnectTimeoutException,
|
||||
SocketTimeoutException, Exception {
|
||||
return postForm(url, params, null, connTimeout, readTimeout);
|
||||
}
|
||||
|
||||
public static String postParameters(String url, Map<String, String> params, Integer connTimeout, Integer readTimeout) throws ConnectTimeoutException,
|
||||
SocketTimeoutException, Exception {
|
||||
return postForm(url, params, null, connTimeout, readTimeout);
|
||||
}
|
||||
|
||||
public static String get(String url) throws Exception {
|
||||
return get(url, charset, null, null);
|
||||
}
|
||||
|
||||
public static String get(String url, String charset) throws Exception {
|
||||
return get(url, charset, connTimeout, readTimeout);
|
||||
}
|
||||
|
||||
public static String getParameters(String url, Map<String, String> params) throws Exception {
|
||||
URIBuilder builder = new URIBuilder(url);
|
||||
if (params != null) {
|
||||
for (String key : params.keySet()) {
|
||||
builder.addParameter(key, params.get(key));
|
||||
}
|
||||
}
|
||||
URI uri = builder.build();
|
||||
return get(uri.toString(), charset, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一个 Post 请求, 使用指定的字符集编码.
|
||||
*
|
||||
* @param url
|
||||
* @param body RequestBody
|
||||
* @param mimeType 例如 application/xml "application/x-www-form-urlencoded" a=1&b=2&c=3
|
||||
* @param charset 编码
|
||||
* @param connTimeout 建立链接超时时间,毫秒.
|
||||
* @param readTimeout 响应超时时间,毫秒.
|
||||
* @return ResponseBody, 使用指定的字符集编码.
|
||||
* @throws ConnectTimeoutException 建立链接超时异常
|
||||
* @throws SocketTimeoutException 响应超时
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String post(String url, String body, String mimeType, String charset, Integer connTimeout, Integer readTimeout)
|
||||
throws ConnectTimeoutException, SocketTimeoutException, Exception {
|
||||
HttpClient client = null;
|
||||
HttpPost post = new HttpPost(url);
|
||||
String result = "";
|
||||
try {
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
HttpEntity entity = new StringEntity(body, ContentType.create(mimeType, charset));
|
||||
post.setEntity(entity);
|
||||
}
|
||||
// 设置参数
|
||||
RequestConfig.Builder customReqConf = RequestConfig.custom();
|
||||
if (connTimeout != null) {
|
||||
customReqConf.setConnectTimeout(connTimeout);
|
||||
}
|
||||
if (readTimeout != null) {
|
||||
customReqConf.setSocketTimeout(readTimeout);
|
||||
}
|
||||
post.setConfig(customReqConf.build());
|
||||
|
||||
HttpResponse res;
|
||||
if (url.startsWith("https")) {
|
||||
// 执行 Https 请求.
|
||||
client = createSSLInsecureClient();
|
||||
res = client.execute(post);
|
||||
} else {
|
||||
// 执行 Http 请求.
|
||||
client = HttpClientUtils.client;
|
||||
res = client.execute(post);
|
||||
}
|
||||
result = EntityUtils.toString(res.getEntity(), charset);
|
||||
} catch (Exception ex) {
|
||||
log.error("HttpClient request error!", ex);
|
||||
throw ex;
|
||||
} finally {
|
||||
post.releaseConnection();
|
||||
if (url.startsWith("https") && client != null && client instanceof CloseableHttpClient) {
|
||||
((CloseableHttpClient) client).close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交form表单
|
||||
*
|
||||
* @param url
|
||||
* @param params
|
||||
* @param connTimeout
|
||||
* @param readTimeout
|
||||
* @return
|
||||
* @throws ConnectTimeoutException
|
||||
* @throws SocketTimeoutException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String postForm(String url, Map<String, String> params, Map<String, String> headers, Integer connTimeout, Integer readTimeout) throws ConnectTimeoutException,
|
||||
SocketTimeoutException, Exception {
|
||||
|
||||
HttpClient client = null;
|
||||
HttpPost post = new HttpPost(url);
|
||||
try {
|
||||
if (params != null && !params.isEmpty()) {
|
||||
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
|
||||
Set<Entry<String, String>> entrySet = params.entrySet();
|
||||
for (Entry<String, String> entry : entrySet) {
|
||||
formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
|
||||
post.setEntity(entity);
|
||||
}
|
||||
|
||||
if (headers != null && !headers.isEmpty()) {
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
post.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
// 设置参数
|
||||
Builder customReqConf = RequestConfig.custom();
|
||||
if (connTimeout != null) {
|
||||
customReqConf.setConnectTimeout(connTimeout);
|
||||
}
|
||||
if (readTimeout != null) {
|
||||
customReqConf.setSocketTimeout(readTimeout);
|
||||
}
|
||||
post.setConfig(customReqConf.build());
|
||||
HttpResponse res = null;
|
||||
if (url.startsWith("https")) {
|
||||
// 执行 Https 请求.
|
||||
client = createSSLInsecureClient();
|
||||
res = client.execute(post);
|
||||
} else {
|
||||
// 执行 Http 请求.
|
||||
client = HttpClientUtils.client;
|
||||
res = client.execute(post);
|
||||
}
|
||||
return EntityUtils.toString(res.getEntity(), charset);
|
||||
} catch (Exception ex) {
|
||||
log.error("HttpClient request error!", ex);
|
||||
throw ex;
|
||||
} finally {
|
||||
post.releaseConnection();
|
||||
if (url.startsWith("https") && client != null
|
||||
&& client instanceof CloseableHttpClient) {
|
||||
((CloseableHttpClient) client).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一个 GET 请求
|
||||
*
|
||||
* @param url
|
||||
* @param charset
|
||||
* @param connTimeout 建立链接超时时间,毫秒.
|
||||
* @param readTimeout 响应超时时间,毫秒.
|
||||
* @return
|
||||
* @throws ConnectTimeoutException 建立链接超时
|
||||
* @throws SocketTimeoutException 响应超时
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String get(String url, String charset, Integer connTimeout, Integer readTimeout)
|
||||
throws ConnectTimeoutException, SocketTimeoutException, Exception {
|
||||
|
||||
HttpClient client = null;
|
||||
HttpGet get = new HttpGet(url);
|
||||
String result = "";
|
||||
try {
|
||||
// 设置参数
|
||||
Builder customReqConf = RequestConfig.custom();
|
||||
if (connTimeout != null) {
|
||||
customReqConf.setConnectTimeout(connTimeout);
|
||||
}
|
||||
if (readTimeout != null) {
|
||||
customReqConf.setSocketTimeout(readTimeout);
|
||||
}
|
||||
get.setConfig(customReqConf.build());
|
||||
|
||||
HttpResponse res = null;
|
||||
|
||||
if (url.startsWith("https")) {
|
||||
// 执行 Https 请求.
|
||||
client = createSSLInsecureClient();
|
||||
res = client.execute(get);
|
||||
} else {
|
||||
// 执行 Http 请求.
|
||||
client = HttpClientUtils.client;
|
||||
res = client.execute(get);
|
||||
}
|
||||
result = EntityUtils.toString(res.getEntity(), charset);
|
||||
} catch (Exception ex) {
|
||||
log.error("HttpClient request error!", ex);
|
||||
throw ex;
|
||||
} finally {
|
||||
get.releaseConnection();
|
||||
if (url.startsWith("https") && client != null && client instanceof CloseableHttpClient) {
|
||||
((CloseableHttpClient) client).close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 response 里获取 charset
|
||||
*
|
||||
* @param ressponse
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private static String getCharsetFromResponse(HttpResponse ressponse) {
|
||||
// Content-Type:text/html; charset=GBK
|
||||
if (ressponse.getEntity() != null && ressponse.getEntity().getContentType() != null && ressponse.getEntity().getContentType().getValue() != null) {
|
||||
String contentType = ressponse.getEntity().getContentType().getValue();
|
||||
if (contentType.contains("charset=")) {
|
||||
return contentType.substring(contentType.indexOf("charset=") + 8);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 SSL连接
|
||||
*
|
||||
* @return
|
||||
* @throws GeneralSecurityException
|
||||
*/
|
||||
private static CloseableHttpClient createSSLInsecureClient() throws GeneralSecurityException {
|
||||
try {
|
||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
return true;
|
||||
}
|
||||
}).build();
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify(String host, SSLSocket ssl)
|
||||
throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify(String host, X509Certificate cert)
|
||||
throws SSLException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify(String host, String[] cns,
|
||||
String[] subjectAlts) throws SSLException {
|
||||
}
|
||||
});
|
||||
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.flossom.miniProgram.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.AlgorithmParameters;
|
||||
|
||||
public class WxCryptUtils {
|
||||
|
||||
/**
|
||||
* 小程序 数据解密
|
||||
*
|
||||
* @param encryptData 加密数据
|
||||
* @param iv 对称解密算法初始向量
|
||||
* @param sessionKey 对称解密秘钥
|
||||
* @return 解密数据
|
||||
*/
|
||||
public static String decrypt(String encryptData, String iv, String sessionKey) throws Exception {
|
||||
AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance("AES");
|
||||
algorithmParameters.init(new IvParameterSpec(Base64.decodeBase64(iv)));
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), algorithmParameters);
|
||||
byte[] decode = PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptData)));
|
||||
String decryptStr = new String(decode, StandardCharsets.UTF_8);
|
||||
return decryptStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据加密
|
||||
*
|
||||
* @param data 需要加密的数据
|
||||
* @param iv 对称加密算法初始向量
|
||||
* @param sessionKey 对称加密秘钥
|
||||
* @return 加密数据
|
||||
*/
|
||||
public static String encrypt(String data, String iv, String sessionKey) throws Exception {
|
||||
AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance("AES");
|
||||
algorithmParameters.init(new IvParameterSpec(Base64.decodeBase64(iv)));
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), algorithmParameters);
|
||||
byte[] textBytes = data.getBytes(StandardCharsets.UTF_8);
|
||||
ByteGroup byteGroup = new ByteGroup();
|
||||
byteGroup.addBytes(textBytes);
|
||||
byte[] padBytes = PKCS7Encoder.encode(byteGroup.size());
|
||||
byteGroup.addBytes(padBytes);
|
||||
byte[] encryptBytes = cipher.doFinal(byteGroup.toBytes());
|
||||
return Base64.encodeBase64String(encryptBytes);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.flossom.miniProgram.mapper.SystemSettingMapper">
|
||||
|
||||
<resultMap type="WxSystemSetting" id="wxSystemSetting">
|
||||
<id property="id" column="id"/>
|
||||
<result property="key" column="key"/>
|
||||
<result property="value" column="value"/>
|
||||
<result property="instructions" column="instructions"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectWxSystemSettingVo">
|
||||
select id,
|
||||
`key`,
|
||||
`value`,
|
||||
instructions,
|
||||
status,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark
|
||||
from wx_system_setting
|
||||
</sql>
|
||||
|
||||
<!-- 查询条件 -->
|
||||
<sql id="sqlwhereSearch">
|
||||
<where>
|
||||
<if test="key !=null">
|
||||
and `key` = #{key}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="getSystemSettingByKey" parameterType="String" resultMap="wxSystemSetting">
|
||||
<include refid="selectWxSystemSettingVo"/>
|
||||
<include refid="sqlwhereSearch"/>
|
||||
order by update_time desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.flossom.miniProgram.mapper.WelcomeMapper">
|
||||
|
||||
<resultMap type="WxWelcomeSetting" id="wxWelcomeSettingResult">
|
||||
<id property="id" column="id" />
|
||||
<result property="title" column="title" />
|
||||
<result property="introduction" column="introduction" />
|
||||
<result property="type" column="type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="url" column="url" />
|
||||
<result property="status" column="status" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectWxWelcomeSettingVo">
|
||||
select id, title, introduction, type, sort, url, status, create_by, create_time, update_by, update_time, remark
|
||||
from wx_welcome_setting
|
||||
</sql>
|
||||
|
||||
<!-- 查询条件 -->
|
||||
<sql id="sqlwhereSearch">
|
||||
<where>
|
||||
<if test="type !=null">
|
||||
and type = #{type}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="obtainWxWlComeSetting" parameterType="Integer" resultMap="wxWelcomeSettingResult">
|
||||
<include refid="selectWxWelcomeSettingVo"/>
|
||||
<include refid="sqlwhereSearch"/>
|
||||
order by sort asc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue