Merge remote-tracking branch 'origin/feature-20240104' into feature-20240104

master
elliott 2 years ago
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;
}
}

@ -78,6 +78,13 @@
<artifactId>flossom-common-swagger</artifactId>
</dependency>
<!-- httpClient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>
<build>

@ -0,0 +1,26 @@
package com.flossom.miniProgram.Enums;
/**
*
* wx_welcome_setting > type
*/
public enum FirstPageTypeEnum {
First_PAGE_VIDEO(1, "启动页视频"), FIRST_WELCOME_IMAGE(2, "欢迎页"), LOGIN_IMAGE(3, "登录页");
private final Integer type;
private final String desc;
FirstPageTypeEnum(Integer type, String desc) {
this.type = type;
this.desc = desc;
}
public Integer getType() {
return type;
}
public String getDesc() {
return desc;
}
}

@ -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;
}
}

@ -1,4 +1,4 @@
package com.flossom.system;
package com.flossom.miniProgram;
import com.flossom.common.security.annotation.EnableCustomConfig;
import com.flossom.common.security.annotation.EnableRyFeignClients;

@ -0,0 +1,53 @@
package com.flossom.miniProgram.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.miniProgram.domain.WxCode2SessionRet;
import com.flossom.miniProgram.utils.MiniProgramUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class LoginController extends BaseController {
@PostMapping("/wx/login")
public AjaxResult getJwt(@RequestParam(value = "code") String code,
@RequestParam(value = "rawData", required = false) String rawData,
@RequestParam(value = "signature", required = false) String signature) throws Exception {
// 1. 使用临时凭证code获取 appi + appsecret + code
WxCode2SessionRet wxCode2SessionRet = JSON.parseObject(MiniProgramUtils.getSessionKeyAndOpenId(code), WxCode2SessionRet.class);
if (0 != wxCode2SessionRet.getErrcode()) {
return AjaxResult.error(wxCode2SessionRet.getErrmsg());
}
// 2.校验签名 小程序发送的签名signature与服务器端生成的签名signature2 = sha1(rawData + sessionKey)
String signature2 = DigestUtils.sha1Hex(rawData + wxCode2SessionRet.getSession_key());
if (!signature.equals(signature2)) {
return AjaxResult.error("签名校验失败");
}
// 5.根据返回的User实体类判断用户是否是新用户是的话将用户信息存到数据库
// 用户非敏感信息rawData
// 签名signature
JSONObject rawDataJson = JSON.parseObject(rawData);
// LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
// lqw.eq(User::getOpenId, openid);
// User user = userService.getOne(lqw);
// if (user == null) {
// // 用户信息入库
// String nickName = rawDataJson.getString("nickName");
// String avatarUrl = rawDataJson.getString("avatarUrl");
// user = new User();
// user.setOpenId(openid);
// user.setAvatar(avatarUrl);
// user.setNickName(nickName);
// userService.save(user);
// }
return AjaxResult.success();
}
}

@ -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,79 @@
package com.flossom.miniProgram.domain;
import com.flossom.common.core.web.domain.BaseEntity;
public class WxSystemSetting extends BaseEntity {
private String id;
/**
*
*/
private String key;
/**
*
*/
private String value;
/**
*
*/
private String instructions;
/**
* 0 1
*/
private String status;
public WxSystemSetting() {
}
public WxSystemSetting(String id, String key, String value, String instructions, String status) {
this.id = id;
this.key = key;
this.value = value;
this.instructions = instructions;
this.status = status;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getInstructions() {
return instructions;
}
public void setInstructions(String instructions) {
this.instructions = instructions;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

@ -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' ,'12',
*/
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,104 @@
package com.flossom.miniProgram.domain;
import com.flossom.common.core.web.domain.BaseEntity;
public class WxWelcomeSetting extends BaseEntity {
private static final long serialVersionUID = 1L;
private String id;
/**
*
*/
private String title;
/**
*
*/
private String introduction;
/**
* 1 2 3 '
*/
private Integer type;
private Integer sort;
/**
*
*/
private String url;
/**
* 0 1
*/
private String status;
public WxWelcomeSetting() {
}
public WxWelcomeSetting(String id, String title, String introduction, Integer type, Integer sort, String url, String status) {
this.id = id;
this.title = title;
this.introduction = introduction;
this.type = type;
this.sort = sort;
this.url = url;
this.status = status;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getIntroduction() {
return introduction;
}
public void setIntroduction(String introduction) {
this.introduction = introduction;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
}

@ -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,19 @@
package com.flossom.miniProgram.mapper;
import com.flossom.miniProgram.domain.WxWelcomeSetting;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface WelcomeMapper {
/**
* typs
*
* @param type 1 2 3
* @return
*/
public List<WxWelcomeSetting> obtainWxWlComeSetting(@Param("type") Integer type);
}

@ -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,52 @@
package com.flossom.miniProgram.utils;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class MiniProgramUtils {
private static final String WX_APPID = "";
private static final String WX_SECRET = "";
private static final String loginUrl = "https://api.weixin.qq.com/sns/jscode2session";
public static String getSessionKeyAndOpenId(String jsCode) throws Exception {
return getSessionKeyAndOpenId(WX_APPID, WX_SECRET, jsCode, "authorization_code");
}
/**
* code openid session_key
* @param appid
* @param secret
* @param jsCode
* @param grant_type
*
*
* {
* "openid":"xxxxxx",
* "session_key":"xxxxx",
* "unionid":"xxxxx",
* "errcode":0,
* "errmsg":"xxxxx"
* }
*
* errcode
* 40029 code js_code
* 45011 api minute-quota reach limit mustslower retry next minute API
* 40226 code blocked
* -1 system error
*/
public static String getSessionKeyAndOpenId(String appid, String secret, String jsCode, String grant_type) throws Exception {
Map<String, String> params = new HashMap<>();
params.put("appid", appid);
params.put("secret", secret);
params.put("jsCode", jsCode);
params.put("grant_type", grant_type);
return HttpClientUtils.getParameters(loginUrl, params);
}
}

@ -0,0 +1,56 @@
package com.flossom.miniProgram.utils;
import java.nio.charset.Charset;
import java.util.Arrays;
public class PKCS7Encoder {
static Charset CHARSET = Charset.forName("utf-8");
static int BLOCK_SIZE = 32;
/**
* .
*
* @param count
* @return
*/
public static byte[] encode(int count) {
// 计算需要填充的位数
int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
if (amountToPad == 0) {
amountToPad = BLOCK_SIZE;
}
// 获得补位所用的字符
char padChr = chr(amountToPad);
String tmp = new String();
for (int index = 0; index < amountToPad; index++) {
tmp += padChr;
}
return tmp.getBytes(CHARSET);
}
/**
*
*
* @param decrypted
* @return
*/
public static byte[] decode(byte[] decrypted) {
int pad = decrypted[decrypted.length - 1];
if (pad < 1 || pad > 32) {
pad = 0;
}
return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
}
/**
* ASCII
*
* @param a
* @return
*/
static char chr(int a) {
byte target = (byte) (a & 0xFF);
return (char) target;
}
}

@ -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);
}
}

@ -23,3 +23,7 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
org.springframework.jdbc.core.JdbcTemplate: DEBUG # 这里使用了Spring Boot默认的数据源连接池若使用其他连接池则根据对应的类名进行调整
com.flossom.miniProgram.mapper: TRACE # 将com.example.mapper替换为自定义Mapper接口的全限定名

@ -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>

@ -35,6 +35,7 @@
<minio.version>8.2.2</minio.version>
<poi.version>4.1.2</poi.version>
<transmittable-thread-local.version>2.14.3</transmittable-thread-local.version>
<hutool.version>5.8.23</hutool.version>
</properties>
<!-- 依赖声明 -->
@ -206,6 +207,14 @@
<version>${flossom.version}</version>
</dependency>
<!-- hutool 工具类 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-bom</artifactId>
<version>${hutool.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save