提交代码

dev-discount
胡锐 3 years ago
parent 0e1623165a
commit 45e867bca3
  1. 2
      hai-bweb/src/main/java/com/bweb/controller/HighTestController.java
  2. 1
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  3. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  4. 72
      hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java
  5. 5
      hai-service/pom.xml
  6. 487
      hai-service/src/main/java/com/hai/common/utils/UnionUtils.java
  7. 80
      hai-service/src/main/java/com/hai/config/UnionUserConfig.java
  8. 11
      hai-service/src/main/java/com/hai/dao/HighUserMapper.java
  9. 28
      hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java
  10. 37
      hai-service/src/main/java/com/hai/entity/HighUser.java
  11. 140
      hai-service/src/main/java/com/hai/entity/HighUserExample.java

@ -1 +1 @@
package com.bweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.HighMerchantModel; import com.hai.model.HighMerchantStoreModel; import com.hai.model.ResponseData; import com.hai.model.ResultProfitSharing; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import java.io.FileInputStream; import java.math.BigDecimal; import java.security.KeyStore; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HighMerchantService highMerchantService; @Resource private HighMerchantStoreService highMerchantStoreService; @Resource private HighGasOilPriceService highGasOilPriceService; @Resource private HighOrderService highOrderService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private UnionPayConfig unionPayConfig; @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(UnionUserConfig.getBackendToken()); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } }
package com.bweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.HighMerchantModel; import com.hai.model.HighMerchantStoreModel; import com.hai.model.ResponseData; import com.hai.model.ResultProfitSharing; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import java.io.FileInputStream; import java.math.BigDecimal; import java.security.KeyStore; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HighMerchantService highMerchantService; @Resource private HighMerchantStoreService highMerchantStoreService; @Resource private HighGasOilPriceService highGasOilPriceService; @Resource private HighOrderService highOrderService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private UnionPayConfig unionPayConfig; @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } }

@ -107,6 +107,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/sms/getSmsCode")
.excludePathPatterns("/activity/getWinLotteryList")
.excludePathPatterns("/user/login")
.excludePathPatterns("/user/unionPhoneLogin")
.excludePathPatterns("/user/getUnionId")
.excludePathPatterns("/order/orderToH5Pay")
.excludePathPatterns("/order/orderToPay")

File diff suppressed because one or more lines are too long

@ -1,5 +1,6 @@
package com.cweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
@ -7,6 +8,8 @@ import com.hai.common.security.*;
import com.hai.common.utils.IDGenerator;
import com.hai.common.utils.RedisUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.UnionUtils;
import com.hai.config.UnionUserConfig;
import com.hai.entity.HighUser;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
@ -41,6 +44,9 @@ public class HighUserCommonController {
@Resource
private RedisUtil redisUtil;
@Resource
private UnionUserConfig unionUserConfig;
@Resource
private UserCenter userCenter;
@ -66,10 +72,73 @@ public class HighUserCommonController {
user = new HighUser();
user.setName("用户" + IDGenerator.nextId(5));
user.setPhone(phone);
user.setRegTime(new Date());
user.setGold(0);
user.setStatus(1);
// 用户信息完整状态
// 0:完整
// 1:需要填写用户信息
// 2:需要填写手机号
user.setInfoCompleteStatus(1);
highUserService.insertUser(user);
}
HighUserModel highUserModel = new HighUserModel();
HighUser detailData = highUserService.getDetailDataByUser(user.getId());
detailData.setPassword(null);
highUserModel.setHighUser(detailData);
SessionObject so = new SessionObject(StringUtils.isNotBlank(user.getUnionId())?user.getUnionId():detailData.getId().toString(), 1 , highUserModel);
userCenter.save(request, response, so);
return ResponseMsgUtil.success(so);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/unionPhoneLogin", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "银联授权手机号登录接口")
public ResponseData unionPhoneLogin(@RequestParam(value = "code", required = true) String code,
HttpServletRequest request, HttpServletResponse response) {
try {
// 获取应用访问令牌
String backendToken = unionUserConfig.getBackendToken();
// 获取授权访问令牌
JSONObject token = unionUserConfig.getAccessToken(backendToken, code);
if (token == null || !token.getString("resp").equals("00")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, token.getString("msg"));
}
// 获取用户手机号
JSONObject userMobile = unionUserConfig.getUserMobile(backendToken, token.getJSONObject("params").getString("accessToken"), token.getJSONObject("params").getString("openId"));
if (userMobile == null || !userMobile.getString("resp").equals("00")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, userMobile.getString("msg"));
}
// 解密,获取手机号
String mobile = UnionUtils.getDecryptedValue(userMobile.getJSONObject("params").getString("mobile"), unionUserConfig.getRsaKey());
HighUser user = highUserService.findByPhone(mobile);
if(user == null) {
user = new HighUser();
user.setName("用户" + IDGenerator.nextId(5));
user.setPhone(mobile);
user.setRegTime(new Date());
user.setGold(0);
user.setUnionOpenId(token.getJSONObject("params").getString("openId"));
user.setUnionUnionId(token.getJSONObject("params").getString("unionId"));
user.setStatus(1);
// 用户信息完整状态
// 0:完整
// 1:需要填写用户信息
// 2:需要填写手机号
user.setInfoCompleteStatus(1);
highUserService.insertUser(user);
} else {
user.setUnionOpenId(token.getJSONObject("params").getString("openId"));
user.setUnionUnionId(token.getJSONObject("params").getString("unionId"));
highUserService.updateUser(user);
}
HighUserModel highUserModel = new HighUserModel();
@ -83,4 +152,7 @@ public class HighUserCommonController {
return ResponseMsgUtil.exception(e);
}
}
}

@ -312,6 +312,11 @@
<artifactId>wechatpay-apache-httpclient</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.16</version>
</dependency>
</dependencies>
<build>
<resources>

@ -0,0 +1,487 @@
package com.hai.common.utils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.client.urlconnection.HTTPSProperties;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.*;
import javax.ws.rs.core.MediaType;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class UnionUtils {
private static Client c = null;
private static Client secureClient =null;
private static Gson gson = new GsonBuilder().disableHtmlEscaping().create();
public static String DATE_FORMAT = "yyyy-MM-dd";
/**
* 初始化设置
*/
static{
initalizationJersyClient();
initalizationSecureJersyClient();
}
/**
* 设置调用参数
*/
private static void initalizationJersyClient(){
try {
c = Client.create();
c.setFollowRedirects(true);
c.setConnectTimeout(10000);
c.setReadTimeout(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void initalizationSecureJersyClient(){
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] chain, String authType)
throws CertificateException {}
public void checkServerTrusted(
java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {}
} }, new SecureRandom());
HostnameVerifier hv = new HostnameVerifier(){
public boolean verify(String urlHostName, SSLSession session){
return true;
}
};
HTTPSProperties prop = new HTTPSProperties(hv, context);
DefaultClientConfig dcc = new DefaultClientConfig();
dcc.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, prop);
secureClient = Client.create(dcc);
secureClient.setFollowRedirects(true);
secureClient.setConnectTimeout(10000);
secureClient.setReadTimeout(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 调用接口
*/
public static String sendPOSTRequest(String url, Object map, String contentTpye){
if(null==c){
initalizationJersyClient();
}
Client client = null;
if(url.indexOf("https://") == 0){
if(null==secureClient){
initalizationJersyClient();
}
client = secureClient;
}else{
if(null==c){
initalizationJersyClient();
}
client = c;
}
WebResource resource = client.resource(url);
String resultStr = null;
try {
Builder builder = resource.accept("*/*");
ClientResponse res = builder.type(contentTpye).entity(map).post(ClientResponse.class);
if(res.getStatus() != 200){
throw new Exception("url:"+url+",response code:" + res.getStatus());
}
resultStr = res.getEntity(String.class);
return resultStr;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 参数 转为json格式
* @param url 调用地址
* @param map 设置的参数
* @return
*/
public static String sendPostGson(String url, Map<String, String> map){
String ps = gson.toJson(map);
System.out.println("生成加密后的报文:"+ps);
return sendPOSTRequest(url, ps, MediaType.APPLICATION_JSON);
}
/**
* 使用公钥加密对称密钥
* @param publicKey 公钥
* @param symmetricKeyByte 对称密钥字节
* @return 加密后的对称密钥字节
* @throws Exception
*/
public static byte[] encrypt(String publicKey, byte[] symmetricKeyByte) throws Exception {
byte[] encodedKey = Base64.decodeBase64(publicKey);
KeySpec keySpec = new X509EncodedKeySpec(encodedKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey pk = keyFactory.generatePublic(keySpec);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, pk);
byte[] result = cipher.doFinal(symmetricKeyByte);
return result;
}
/**
* 签名加密后的数据装载进map
* @param key 对称秘钥
* @param params 待加密的字符串
* @param encryptKeys 加密字段
* @throws Exception
*/
public static void encryptedParamMap(String key, Map<String, String> params, String ... encryptKeys) throws Exception{
if(encryptKeys != null && encryptKeys.length > 0){
for(String encryptKey : encryptKeys){
params.put(encryptKey, getEncryptedValue(params.get(encryptKey), key));
}
}
}
/**
* 3DES加密
* @param value 待加密的字符串
* @param key 加密密钥
* @return 加密后的字符串
* @throws Exception
*/
public static String getEncryptedValue(String value, String key) throws Exception {
if (null == value || "".equals(value)) {
return "";
}
byte[] valueByte = value.getBytes();
byte[] sl = encrypt3DES(valueByte, hexToBytes(key));
String result = Base64.encodeBase64String(sl);
// String result = BytesUtil.bytesToHex(sl);
return result;
}
/**
* 解密
* @param value 待解密的字符串
* @param key 解密秘钥
* @return 解密后字符串
* @throws Exception
*/
public static String getDecryptedValue(String value, String key) throws Exception {
if (null == value || "".equals(value)) {
return "";
}
byte[] valueByte = Base64.decodeBase64(value);
byte[] sl = decrypt3DES(valueByte, hexStr2Bytes(key));
String result = new String(sl);
return result;
}
/**
* 3DES解密
* @param input
* @param key
* @return
* @throws Exception
*/
public static byte[] decrypt3DES(byte[] input, byte[] key) throws Exception {
Cipher c = Cipher.getInstance("DESede/ECB/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "DESede"));
return c.doFinal(input);
}
/**
* bytes字符串转换为Byte值
* @param src String Byte字符串每个Byte之间没有分隔符(字符范围:0-9 A-F)
* @return byte[]
*/
public static byte[] hexStr2Bytes(String src){
/*对输入值进行规范化整理*/
src = src.trim().replace(" ", "").toUpperCase(Locale.US);
//处理值初始化
int m=0,n=0;
int iLen=src.length()/2; //计算长度
byte[] ret = new byte[iLen]; //分配存储空间
for (int i = 0; i < iLen; i++){
m=i*2+1;
n=m+1;
ret[i] = (byte)(Integer.decode("0x"+ src.substring(i*2, m) + src.substring(m,n)) & 0xFF);
}
return ret;
}
/**
* 3DES加密
* @param input 待加密的字节
* @param key 密钥
* @return 加密后的字节
* @throws Exception
*/
private static byte[] encrypt3DES(byte[] input, byte[] key) throws Exception {
Cipher c = Cipher.getInstance("DESede/ECB/PKCS5Padding");
c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DESede"));
return c.doFinal(input);
}
/**
* 获取随机字符串
* @return 随机字符串
*/
public static String createNonceStr(){
String sl = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < 16 ; i ++){
sb.append(sl.charAt(new Random().nextInt(sl.length())));
}
return sb.toString();
}
/**
* h获取32位随机数字字符串
* @return
*/
public static String createNonceNumber(){
String sl = "0123456789";
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < 32 ; i ++){
sb.append(sl.charAt(new Random().nextInt(sl.length())));
}
return sb.toString();
}
/**
* 获取当前日期时间
*
* @return
*/
public static String getCurrentDateTime(String Dateformat) {
String datestr = null;
SimpleDateFormat df = new SimpleDateFormat(Dateformat);
datestr = df.format(new Date());
return datestr;
}
/**
* 在输入日期上增加+或减去-天数
*
* @param date 输入日期
*/
public static Date addDay(Date date, int iday) {
Calendar cd = Calendar.getInstance();
cd.setTime(date);
cd.add(Calendar.DAY_OF_MONTH, iday);
return cd.getTime();
}
/**
* 将日期格式日期转换为字符串格式 自定義格式
*
* @param date
* @param dateformat
* @return
*/
public static String dateToString(Date date, String dateformat) {
String datestr = null;
SimpleDateFormat df = new SimpleDateFormat(dateformat);
datestr = df.format(date);
return datestr;
}
/**
* 将字符串日期转换为日期格式
*
* @param datestr
* @return
*/
public static Date stringToDate(String datestr) throws Exception{
if (datestr == null || datestr.equals("")) {
return null;
}
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
try {
date = df.parse(datestr);
} catch (ParseException e) {
date = stringToDate(datestr, "yyyyMMdd");
}
return date;
}
/**
* 将字符串日期转换为日期格式
* 自定義格式
*
* @param datestr
* @return
*/
public static Date stringToDate(String datestr, String dateformat) throws Exception{
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat(dateformat);
date = df.parse(datestr);
return date;
}
/**
* 签名
* @param param 待签名的参数
* @param signKey 签名密钥
* @return 签名结果字符串
* @throws Exception
*/
public static String sign(Map<String, String> param, String signKey) throws Exception {
String value = sortMap(param);
byte[] keyBytes = Base64.decodeBase64(signKey);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyf = KeyFactory.getInstance("RSA");
PrivateKey priKey = keyf.generatePrivate(keySpec);
Signature signature = Signature.getInstance("SHA256WithRSA");
signature.initSign(priKey);
signature.update(value.getBytes());
byte[] signed = signature.sign();
String result = Base64.encodeBase64String(signed);
return result;
}
/**
* 排序
* @param param 待排序的参数
* @return 排序结果字符串
*/
public static String sortMap(Map<String, String> param){
StringBuilder result = new StringBuilder();
Collection<String> keySet = param.keySet();
List<String> list = new ArrayList<String>(keySet);
Collections.sort(list);
for (int i = 0; i < list.size(); ++i) {
String key = list.get(i);
if("symmetricKey".equals(key)){
continue;
}
// 非空字段需要参与签名
// if(param.get(key) == null || "".equals(param.get(key).trim())){
// continue;
// }
result.append(key).append("=").append(param.get(key)).append("&");
}
return result.substring(0, result.length() - 1);
}
public static String sha256(byte[] data) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
return bytesToHex(md.digest(data));
} catch (Exception ex) {
return null;
}
}
/**
* 将byte数组转换成16进制字符串
*
* @param bytes
* @return 16进制字符串
*/
public static String bytesToHex(byte[] bytes) {
String hexArray = "0123456789abcdef";
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
int bi = b & 0xff;
sb.append(hexArray.charAt(bi >> 4));
sb.append(hexArray.charAt(bi & 0xf));
}
return sb.toString();
}
public static byte[] hexToBytes(String hex) {
return hexToBytes(hex.toCharArray());
}
public static byte[] hexToBytes(char[] hex) {
int length = hex.length / 2;
byte[] raw = new byte[length];
for (int i = 0; i < length; i++) {
int high = Character.digit(hex[i * 2], 16);
int low = Character.digit(hex[i * 2 + 1], 16);
int value = (high << 4) | low;
if (value > 127) {
value -= 256;
}
raw[i] = (byte) value;
}
return raw;
}
public static String createSign(Map<String, String> params){
StringBuilder sb = new StringBuilder();
// 将参数以参数名的字典升序排序
Map<String, String> sortParams = new TreeMap<String, String>(params);
// 遍历排序的字典,并拼接"key=value"格式
for (Map.Entry<String, String> entry : sortParams.entrySet()) {
String key = entry.getKey();
String value = entry.getValue().trim();
if (null != value && !"".equals(value))
sb.append("&").append(key).append("=").append(value);
}
String stringA = sb.toString().replaceFirst("&","");
String stringSignTemp = stringA ;
String signValue = sha256(stringSignTemp.getBytes());
return signValue;
}
/**
* 签名
* @param param 待签名的参数
* @param sign 签名结果字符串
* @return 签名结果
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws InvalidKeyException
* @throws SignatureException
*/
public static boolean verify(Map<String, String> param, String sign,String rescissionPublicKey) throws Exception {
String value = sortMap(param);
byte[] keyBytes = Base64.decodeBase64(rescissionPublicKey);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyf = KeyFactory.getInstance("RSA");
PublicKey pubkey = keyf.generatePublic(keySpec);
Signature signature = Signature.getInstance("SHA256WithRSA");
signature.initVerify(pubkey);
signature.update(value.getBytes());
boolean result = signature.verify(Base64.decodeBase64(sign.getBytes()));
return result;
}
}

@ -4,8 +4,13 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.RedisUtil;
import com.hai.common.utils.UnionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.DatatypeConverter;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
@ -19,23 +24,75 @@ import java.util.*;
* 银联用户信息
* @author hurui
*/
@Component
public class UnionUserConfig {
private static String requestUrl = "https://open.95516.com/open/access/1.0/backendToken";
private static String appId = "1900bc84497cab3b";
private static String requestUrl = "https://open.95516.com/open/access/1.0/";
private static String appId = "cf56ac6f9f6b4744bfba9e5587db147c";
private static String secret = "665193ddd44248acb461594cfe0ded5b";
private static String rsaKey = "df0bdf7f5ef7bff770f2f21fe549c461df0bdf7f5ef7bff7";
@Resource
private RedisUtil redisUtil;
/**
* 获取应用访问令牌backendToken
* @return
*/
public static JSONObject getBackendToken() {
Map<String,Object> paramMap = new HashMap<>();
public String getBackendToken() {
Object token = redisUtil.get("UNION_BACKEND_TOKEN");
if (token != null) {
return token.toString();
}
Map<String,String> paramMap = new HashMap<>();
paramMap.put("appId", appId);
paramMap.put("secret", secret);
paramMap.put("nonceStr", UnionUtils.createNonceStr());
paramMap.put("timestamp", String.valueOf(System.currentTimeMillis()/1000));
paramMap.put("signature", generateSign(paramMap));
paramMap.remove("secret");
JSONObject jsonObject = JSONObject.parseObject(UnionUtils.sendPostGson(requestUrl+"backendToken", paramMap));
String backendToken = jsonObject.getJSONObject("params").getString("backendToken");
redisUtil.set("UNION_BACKEND_TOKEN", backendToken,jsonObject.getJSONObject("params").getLong("expiresIn"));
return backendToken;
}
/**
* 获取授权访问令牌accessToken
* @return
*/
public JSONObject getAccessToken(String backendToken,String code) {
Map<String,String> paramMap = new HashMap<>();
paramMap.put("appId", appId);
paramMap.put("secret", secret);
paramMap.put("nonceStr", UnionUtils.createNonceStr());
paramMap.put("timestamp", String.valueOf(System.currentTimeMillis()/1000));
paramMap.put("backendToken", backendToken);
paramMap.put("code", code);
paramMap.put("grantType", "authorization_code");
paramMap.put("signature", generateSign(paramMap));
paramMap.remove("secret");
return JSONObject.parseObject(UnionUtils.sendPostGson(requestUrl+"token", paramMap));
}
/**
* 获取用户手机号
* @return
*/
public JSONObject getUserMobile(String backendToken,String accessToken,String openId) {
Map<String,String> paramMap = new HashMap<>();
paramMap.put("appId", appId);
paramMap.put("nonceStr", createNonceStr());
paramMap.put("timestamp", System.currentTimeMillis());
paramMap.put("secret", secret);
paramMap.put("nonceStr", UnionUtils.createNonceStr());
paramMap.put("timestamp", String.valueOf(System.currentTimeMillis()/1000));
paramMap.put("backendToken", backendToken);
paramMap.put("accessToken", accessToken);
paramMap.put("openId", openId);
paramMap.put("signature", generateSign(paramMap));
return HttpsUtils.doPost(requestUrl, JSONObject.toJSONString(paramMap));
paramMap.remove("secret");
return JSONObject.parseObject(UnionUtils.sendPostGson(requestUrl+"user.mobile", paramMap));
}
@ -44,7 +101,7 @@ public class UnionUserConfig {
* @param param
* @return
*/
private static String paramSort(final Map<String, Object> param) {
private static String paramSort(final Map<String, String> param) {
Set<String> keySet = param.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]);
Arrays.sort(keyArray);
@ -59,7 +116,6 @@ public class UnionUserConfig {
sb.append("&").append(k).append("=").append(param.get(k));
}
}
param.remove("secret");
return sb.toString();
}
@ -69,7 +125,7 @@ public class UnionUserConfig {
* @return
* @throws Exception
*/
private static String generateSign(Map<String, Object> data){
private static String generateSign(Map<String, String> data){
data.put("secret", secret);
String sign = sha256(paramSort(data).getBytes());
return sign;
@ -88,6 +144,10 @@ public class UnionUserConfig {
return sb.toString();
}
public String getRsaKey(){
return rsaKey;
}
public static String sha256(byte[] data) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");

@ -44,6 +44,7 @@ public interface HighUserMapper extends HighUserMapperExt {
"sex, birthdate, reg_time, ",
"gold, `status`, open_id, ",
"open_id_h5, union_id, ",
"union_open_id, union_union_id, ",
"info_complete_status, ext_1, ",
"ext_2, ext_3, ext_4)",
"values (#{headerImg,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ",
@ -51,6 +52,7 @@ public interface HighUserMapper extends HighUserMapperExt {
"#{sex,jdbcType=VARCHAR}, #{birthdate,jdbcType=DATE}, #{regTime,jdbcType=TIMESTAMP}, ",
"#{gold,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR}, ",
"#{openIdH5,jdbcType=VARCHAR}, #{unionId,jdbcType=VARCHAR}, ",
"#{unionOpenId,jdbcType=VARCHAR}, #{unionUnionId,jdbcType=VARCHAR}, ",
"#{infoCompleteStatus,jdbcType=INTEGER}, #{ext1,jdbcType=VARCHAR}, ",
"#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR}, #{ext4,jdbcType=VARCHAR})"
})
@ -76,6 +78,8 @@ public interface HighUserMapper extends HighUserMapperExt {
@Result(column="open_id", property="openId", jdbcType=JdbcType.VARCHAR),
@Result(column="open_id_h5", property="openIdH5", jdbcType=JdbcType.VARCHAR),
@Result(column="union_id", property="unionId", jdbcType=JdbcType.VARCHAR),
@Result(column="union_open_id", property="unionOpenId", jdbcType=JdbcType.VARCHAR),
@Result(column="union_union_id", property="unionUnionId", jdbcType=JdbcType.VARCHAR),
@Result(column="info_complete_status", property="infoCompleteStatus", jdbcType=JdbcType.INTEGER),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
@ -87,7 +91,8 @@ public interface HighUserMapper extends HighUserMapperExt {
@Select({
"select",
"id, header_img, `name`, phone, `password`, sex, birthdate, reg_time, gold, `status`, ",
"open_id, open_id_h5, union_id, info_complete_status, ext_1, ext_2, ext_3, ext_4",
"open_id, open_id_h5, union_id, union_open_id, union_union_id, info_complete_status, ",
"ext_1, ext_2, ext_3, ext_4",
"from high_user",
"where id = #{id,jdbcType=BIGINT}"
})
@ -105,6 +110,8 @@ public interface HighUserMapper extends HighUserMapperExt {
@Result(column="open_id", property="openId", jdbcType=JdbcType.VARCHAR),
@Result(column="open_id_h5", property="openIdH5", jdbcType=JdbcType.VARCHAR),
@Result(column="union_id", property="unionId", jdbcType=JdbcType.VARCHAR),
@Result(column="union_open_id", property="unionOpenId", jdbcType=JdbcType.VARCHAR),
@Result(column="union_union_id", property="unionUnionId", jdbcType=JdbcType.VARCHAR),
@Result(column="info_complete_status", property="infoCompleteStatus", jdbcType=JdbcType.INTEGER),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
@ -136,6 +143,8 @@ public interface HighUserMapper extends HighUserMapperExt {
"open_id = #{openId,jdbcType=VARCHAR},",
"open_id_h5 = #{openIdH5,jdbcType=VARCHAR},",
"union_id = #{unionId,jdbcType=VARCHAR},",
"union_open_id = #{unionOpenId,jdbcType=VARCHAR},",
"union_union_id = #{unionUnionId,jdbcType=VARCHAR},",
"info_complete_status = #{infoCompleteStatus,jdbcType=INTEGER},",
"ext_1 = #{ext1,jdbcType=VARCHAR},",
"ext_2 = #{ext2,jdbcType=VARCHAR},",

@ -76,6 +76,14 @@ public class HighUserSqlProvider {
sql.VALUES("union_id", "#{unionId,jdbcType=VARCHAR}");
}
if (record.getUnionOpenId() != null) {
sql.VALUES("union_open_id", "#{unionOpenId,jdbcType=VARCHAR}");
}
if (record.getUnionUnionId() != null) {
sql.VALUES("union_union_id", "#{unionUnionId,jdbcType=VARCHAR}");
}
if (record.getInfoCompleteStatus() != null) {
sql.VALUES("info_complete_status", "#{infoCompleteStatus,jdbcType=INTEGER}");
}
@ -118,6 +126,8 @@ public class HighUserSqlProvider {
sql.SELECT("open_id");
sql.SELECT("open_id_h5");
sql.SELECT("union_id");
sql.SELECT("union_open_id");
sql.SELECT("union_union_id");
sql.SELECT("info_complete_status");
sql.SELECT("ext_1");
sql.SELECT("ext_2");
@ -192,6 +202,14 @@ public class HighUserSqlProvider {
sql.SET("union_id = #{record.unionId,jdbcType=VARCHAR}");
}
if (record.getUnionOpenId() != null) {
sql.SET("union_open_id = #{record.unionOpenId,jdbcType=VARCHAR}");
}
if (record.getUnionUnionId() != null) {
sql.SET("union_union_id = #{record.unionUnionId,jdbcType=VARCHAR}");
}
if (record.getInfoCompleteStatus() != null) {
sql.SET("info_complete_status = #{record.infoCompleteStatus,jdbcType=INTEGER}");
}
@ -233,6 +251,8 @@ public class HighUserSqlProvider {
sql.SET("open_id = #{record.openId,jdbcType=VARCHAR}");
sql.SET("open_id_h5 = #{record.openIdH5,jdbcType=VARCHAR}");
sql.SET("union_id = #{record.unionId,jdbcType=VARCHAR}");
sql.SET("union_open_id = #{record.unionOpenId,jdbcType=VARCHAR}");
sql.SET("union_union_id = #{record.unionUnionId,jdbcType=VARCHAR}");
sql.SET("info_complete_status = #{record.infoCompleteStatus,jdbcType=INTEGER}");
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}");
@ -296,6 +316,14 @@ public class HighUserSqlProvider {
sql.SET("union_id = #{unionId,jdbcType=VARCHAR}");
}
if (record.getUnionOpenId() != null) {
sql.SET("union_open_id = #{unionOpenId,jdbcType=VARCHAR}");
}
if (record.getUnionUnionId() != null) {
sql.SET("union_union_id = #{unionUnionId,jdbcType=VARCHAR}");
}
if (record.getInfoCompleteStatus() != null) {
sql.SET("info_complete_status = #{infoCompleteStatus,jdbcType=INTEGER}");
}

@ -75,7 +75,20 @@ public class HighUser extends UserModel implements Serializable {
private String unionId;
/**
* 用户信息完整状态 0完整 1需要填写用户信息 2需要填写手机号
* 银联用户唯一标识
*/
private String unionOpenId;
/**
* 银联统一用户标识
*/
private String unionUnionId;
/**
* 用户信息完整状态
0完整
1需要填写用户信息
2需要填写手机号
*/
private Integer infoCompleteStatus;
@ -193,6 +206,22 @@ public class HighUser extends UserModel implements Serializable {
this.unionId = unionId;
}
public String getUnionOpenId() {
return unionOpenId;
}
public void setUnionOpenId(String unionOpenId) {
this.unionOpenId = unionOpenId;
}
public String getUnionUnionId() {
return unionUnionId;
}
public void setUnionUnionId(String unionUnionId) {
this.unionUnionId = unionUnionId;
}
public Integer getInfoCompleteStatus() {
return infoCompleteStatus;
}
@ -258,6 +287,8 @@ public class HighUser extends UserModel implements Serializable {
&& (this.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
&& (this.getOpenIdH5() == null ? other.getOpenIdH5() == null : this.getOpenIdH5().equals(other.getOpenIdH5()))
&& (this.getUnionId() == null ? other.getUnionId() == null : this.getUnionId().equals(other.getUnionId()))
&& (this.getUnionOpenId() == null ? other.getUnionOpenId() == null : this.getUnionOpenId().equals(other.getUnionOpenId()))
&& (this.getUnionUnionId() == null ? other.getUnionUnionId() == null : this.getUnionUnionId().equals(other.getUnionUnionId()))
&& (this.getInfoCompleteStatus() == null ? other.getInfoCompleteStatus() == null : this.getInfoCompleteStatus().equals(other.getInfoCompleteStatus()))
&& (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1()))
&& (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2()))
@ -282,6 +313,8 @@ public class HighUser extends UserModel implements Serializable {
result = prime * result + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
result = prime * result + ((getOpenIdH5() == null) ? 0 : getOpenIdH5().hashCode());
result = prime * result + ((getUnionId() == null) ? 0 : getUnionId().hashCode());
result = prime * result + ((getUnionOpenId() == null) ? 0 : getUnionOpenId().hashCode());
result = prime * result + ((getUnionUnionId() == null) ? 0 : getUnionUnionId().hashCode());
result = prime * result + ((getInfoCompleteStatus() == null) ? 0 : getInfoCompleteStatus().hashCode());
result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode());
result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode());
@ -309,6 +342,8 @@ public class HighUser extends UserModel implements Serializable {
sb.append(", openId=").append(openId);
sb.append(", openIdH5=").append(openIdH5);
sb.append(", unionId=").append(unionId);
sb.append(", unionOpenId=").append(unionOpenId);
sb.append(", unionUnionId=").append(unionUnionId);
sb.append(", infoCompleteStatus=").append(infoCompleteStatus);
sb.append(", ext1=").append(ext1);
sb.append(", ext2=").append(ext2);

@ -1012,6 +1012,146 @@ public class HighUserExample {
return (Criteria) this;
}
public Criteria andUnionOpenIdIsNull() {
addCriterion("union_open_id is null");
return (Criteria) this;
}
public Criteria andUnionOpenIdIsNotNull() {
addCriterion("union_open_id is not null");
return (Criteria) this;
}
public Criteria andUnionOpenIdEqualTo(String value) {
addCriterion("union_open_id =", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdNotEqualTo(String value) {
addCriterion("union_open_id <>", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdGreaterThan(String value) {
addCriterion("union_open_id >", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdGreaterThanOrEqualTo(String value) {
addCriterion("union_open_id >=", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdLessThan(String value) {
addCriterion("union_open_id <", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdLessThanOrEqualTo(String value) {
addCriterion("union_open_id <=", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdLike(String value) {
addCriterion("union_open_id like", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdNotLike(String value) {
addCriterion("union_open_id not like", value, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdIn(List<String> values) {
addCriterion("union_open_id in", values, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdNotIn(List<String> values) {
addCriterion("union_open_id not in", values, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdBetween(String value1, String value2) {
addCriterion("union_open_id between", value1, value2, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionOpenIdNotBetween(String value1, String value2) {
addCriterion("union_open_id not between", value1, value2, "unionOpenId");
return (Criteria) this;
}
public Criteria andUnionUnionIdIsNull() {
addCriterion("union_union_id is null");
return (Criteria) this;
}
public Criteria andUnionUnionIdIsNotNull() {
addCriterion("union_union_id is not null");
return (Criteria) this;
}
public Criteria andUnionUnionIdEqualTo(String value) {
addCriterion("union_union_id =", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdNotEqualTo(String value) {
addCriterion("union_union_id <>", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdGreaterThan(String value) {
addCriterion("union_union_id >", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdGreaterThanOrEqualTo(String value) {
addCriterion("union_union_id >=", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdLessThan(String value) {
addCriterion("union_union_id <", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdLessThanOrEqualTo(String value) {
addCriterion("union_union_id <=", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdLike(String value) {
addCriterion("union_union_id like", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdNotLike(String value) {
addCriterion("union_union_id not like", value, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdIn(List<String> values) {
addCriterion("union_union_id in", values, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdNotIn(List<String> values) {
addCriterion("union_union_id not in", values, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdBetween(String value1, String value2) {
addCriterion("union_union_id between", value1, value2, "unionUnionId");
return (Criteria) this;
}
public Criteria andUnionUnionIdNotBetween(String value1, String value2) {
addCriterion("union_union_id not between", value1, value2, "unionUnionId");
return (Criteria) this;
}
public Criteria andInfoCompleteStatusIsNull() {
addCriterion("info_complete_status is null");
return (Criteria) this;

Loading…
Cancel
Save