From 45e867bca3216bd76efd4936bf7e328b9b6a6f80 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 23 Nov 2021 22:44:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bweb/controller/HighTestController.java | 2 +- .../main/java/com/cweb/config/AuthConfig.java | 1 + .../cweb/controller/HighTestController.java | 2 +- .../controller/HighUserCommonController.java | 72 +++ hai-service/pom.xml | 5 + .../java/com/hai/common/utils/UnionUtils.java | 487 ++++++++++++++++++ .../java/com/hai/config/UnionUserConfig.java | 80 ++- .../main/java/com/hai/dao/HighUserMapper.java | 11 +- .../java/com/hai/dao/HighUserSqlProvider.java | 28 + .../main/java/com/hai/entity/HighUser.java | 37 +- .../java/com/hai/entity/HighUserExample.java | 140 +++++ 11 files changed, 851 insertions(+), 14 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/common/utils/UnionUtils.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java index ca89a70d..697c01d6 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.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); } } } \ No newline at end of file +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); } } } \ No newline at end of file diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 04aea895..8d876b53 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -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") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java index ebb644c7..da378f24 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java @@ -1 +1 @@ -package com.cweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; 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.*; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; 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.*; 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 = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "初始化加油站") public ResponseData initTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); for (int i = 1; i <= resultObjectP.getInteger("totalPageNum").intValue();i++) { JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); HighMerchantStore highMerchantStore; HighGasOilPrice highGasOilPrice; for (Object gasObject : jsonArray) { JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); if (store != null) { store.setType(1); store.setMerchantId(merchant.getId()); store.setCompanyId(merchant.getCompanyId()); store.setStoreKey(object.getString("gasId")); store.setStoreName(object.getString("gasName")); store.setStoreLogo(object.getString("gasLogoSmall")); store.setRegionId(object.getLong("provinceCode")); store.setRegionName(object.getString("provinceName")); store.setAddress(object.getString("gasAddress")); store.setLongitude(object.getString("gasAddressLongitude")); store.setLatitude(object.getString("gasAddressLatitude")); store.setStatus(object.getInteger("gasStatus")); store.setOperatorId(0L); store.setOperatorName("系统创建"); store.setUpdateTime(new Date()); store.setExt1(object.getString("gasSourceId")); highMerchantStoreService.updateMerchantStoreDetail(store); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); // 查询门店油号 highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); if (highGasOilPrice == null) { highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } else { highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } else { highMerchantStore = new HighMerchantStore(); highMerchantStore.setType(1); highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setCompanyId(merchant.getCompanyId()); highMerchantStore.setStoreKey(object.getString("gasId")); highMerchantStore.setStoreName(object.getString("gasName")); highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); highMerchantStore.setRegionId(object.getLong("provinceCode")); highMerchantStore.setRegionName(object.getString("provinceName")); highMerchantStore.setAddress(object.getString("gasAddress")); highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); highMerchantStore.setStatus(1); highMerchantStore.setOperatorId(0L); highMerchantStore.setOperatorName("系统创建"); highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setExt1(object.getString("gasSourceId")); HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); highMerchantStoreService.insertMerchantStore(merchantStoreModel); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } } } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/pushTuanYouOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "推送团油订单") public ResponseData pushTuanYouOrder() { try { HighOrder order = highOrderService.getOrderByOrderNo("HF2021102112141171406"); for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); // 推送团油订单 Map paramMap = new HashMap<>(); paramMap.put("gasId", store.getStoreKey()); paramMap.put("oilNo", highChildOrder.getGasOilNo()); paramMap.put("gunNo", highChildOrder.getGasGunNo()); BigDecimal priceGun = highChildOrder.getGasPriceGun(); BigDecimal priceVip = highChildOrder.getGasPriceVip(); paramMap.put("priceGun", priceGun); // 枪单价 paramMap.put("priceVip", priceVip); // 优惠价 paramMap.put("driverPhone", order.getMemPhone()); // paramMap.put("driverPhone", "17726395120"); paramMap.put("thirdSerialNo", order.getOrderNo()); paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); // 油品类型 1:汽油:2:柴油;3:天然气 if (highChildOrder.getGasOilType() == 1) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); } else if (highChildOrder.getGasOilType() == 2) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); } JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); // 推送团油订单记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(orderPushObject.getString("code")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } highOrderService.updateOrder(order); } return ResponseMsgUtil.success(order); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyAccountInfo2JD", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyAccountInfo2JD() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD()); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(HuiLianTongConfig.couJointDist(token,"HF"+System.currentTimeMillis(),"20JY000251",2,"17726395120", "oArhO6XxKSvjI9wLP3cTK-iSG8yY")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联支付") public ResponseData unionPay() { try { return ResponseMsgUtil.success(unionPayConfig.upPreOrder("HF"+System.currentTimeMillis(), new BigDecimal("1"), "test",CommonSysConst.getSysConfig().getUnionPayNotifyUrl())); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取贵州中石化token") public ResponseData getToken() { try { return ResponseMsgUtil.success(huiLianTongConfig.getToken()); } catch (Exception e) { log.error("HighOrderController --> getToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionTradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联交易查询") public ResponseData unionTradeQuery(@RequestParam(name = "paySerialNo", required = true) String paySerialNo) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(paySerialNo)); } catch (Exception e) { log.error("HighOrderController --> unionTradeQuery() error!", e); return ResponseMsgUtil.exception(e); } } @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); } } @RequestMapping(value = "/wxSplitAccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "微信分账") public ResponseData wxSplitAccount() { try { HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); wxProfitsharing(orderNo.getOrderNo(),orderNo.getPaySerialNo(),orderNo.getPayRealPrice()); return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); if (!resultProfitSharing.getResult_code().equals("FAIL")) { HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } public CloseableHttpClient readCertificate(String mchId) throws Exception{ /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); // Allow TLSv1 protocol only return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } } \ No newline at end of file +package com.cweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; 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.*; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; 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.*; 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; @Resource private UnionUserConfig unionUserConfig; @RequestMapping(value = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "初始化加油站") public ResponseData initTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); for (int i = 1; i <= resultObjectP.getInteger("totalPageNum").intValue();i++) { JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); HighMerchantStore highMerchantStore; HighGasOilPrice highGasOilPrice; for (Object gasObject : jsonArray) { JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); if (store != null) { store.setType(1); store.setMerchantId(merchant.getId()); store.setCompanyId(merchant.getCompanyId()); store.setStoreKey(object.getString("gasId")); store.setStoreName(object.getString("gasName")); store.setStoreLogo(object.getString("gasLogoSmall")); store.setRegionId(object.getLong("provinceCode")); store.setRegionName(object.getString("provinceName")); store.setAddress(object.getString("gasAddress")); store.setLongitude(object.getString("gasAddressLongitude")); store.setLatitude(object.getString("gasAddressLatitude")); store.setStatus(object.getInteger("gasStatus")); store.setOperatorId(0L); store.setOperatorName("系统创建"); store.setUpdateTime(new Date()); store.setExt1(object.getString("gasSourceId")); highMerchantStoreService.updateMerchantStoreDetail(store); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); // 查询门店油号 highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); if (highGasOilPrice == null) { highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } else { highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } else { highMerchantStore = new HighMerchantStore(); highMerchantStore.setType(1); highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setCompanyId(merchant.getCompanyId()); highMerchantStore.setStoreKey(object.getString("gasId")); highMerchantStore.setStoreName(object.getString("gasName")); highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); highMerchantStore.setRegionId(object.getLong("provinceCode")); highMerchantStore.setRegionName(object.getString("provinceName")); highMerchantStore.setAddress(object.getString("gasAddress")); highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); highMerchantStore.setStatus(1); highMerchantStore.setOperatorId(0L); highMerchantStore.setOperatorName("系统创建"); highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setExt1(object.getString("gasSourceId")); HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); highMerchantStoreService.insertMerchantStore(merchantStoreModel); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } } } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/pushTuanYouOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "推送团油订单") public ResponseData pushTuanYouOrder() { try { HighOrder order = highOrderService.getOrderByOrderNo("HF2021102112141171406"); for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); // 推送团油订单 Map paramMap = new HashMap<>(); paramMap.put("gasId", store.getStoreKey()); paramMap.put("oilNo", highChildOrder.getGasOilNo()); paramMap.put("gunNo", highChildOrder.getGasGunNo()); BigDecimal priceGun = highChildOrder.getGasPriceGun(); BigDecimal priceVip = highChildOrder.getGasPriceVip(); paramMap.put("priceGun", priceGun); // 枪单价 paramMap.put("priceVip", priceVip); // 优惠价 paramMap.put("driverPhone", order.getMemPhone()); // paramMap.put("driverPhone", "17726395120"); paramMap.put("thirdSerialNo", order.getOrderNo()); paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); // 油品类型 1:汽油:2:柴油;3:天然气 if (highChildOrder.getGasOilType() == 1) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); } else if (highChildOrder.getGasOilType() == 2) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); } JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); // 推送团油订单记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(orderPushObject.getString("code")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } highOrderService.updateOrder(order); } return ResponseMsgUtil.success(order); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyAccountInfo2JD", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyAccountInfo2JD() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD()); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(HuiLianTongConfig.couJointDist(token,"HF"+System.currentTimeMillis(),"20JY000251",2,"17726395120", "oArhO6XxKSvjI9wLP3cTK-iSG8yY")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联支付") public ResponseData unionPay() { try { return ResponseMsgUtil.success(unionPayConfig.upPreOrder("HF"+System.currentTimeMillis(), new BigDecimal("1"), "test",CommonSysConst.getSysConfig().getUnionPayNotifyUrl())); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取贵州中石化token") public ResponseData getToken() { try { return ResponseMsgUtil.success(huiLianTongConfig.getToken()); } catch (Exception e) { log.error("HighOrderController --> getToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionTradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联交易查询") public ResponseData unionTradeQuery(@RequestParam(name = "paySerialNo", required = true) String paySerialNo) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(paySerialNo)); } catch (Exception e) { log.error("HighOrderController --> unionTradeQuery() error!", e); return ResponseMsgUtil.exception(e); } } @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); } } @RequestMapping(value = "/wxSplitAccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "微信分账") public ResponseData wxSplitAccount() { try { HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); wxProfitsharing(orderNo.getOrderNo(),orderNo.getPaySerialNo(),orderNo.getPayRealPrice()); return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); if (!resultProfitSharing.getResult_code().equals("FAIL")) { HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } public CloseableHttpClient readCertificate(String mchId) throws Exception{ /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); // Allow TLSv1 protocol only return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } } \ No newline at end of file diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java index 43de0c4b..264287f3 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java @@ -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); } } + } + + diff --git a/hai-service/pom.xml b/hai-service/pom.xml index 73db3b71..d4d4ac36 100644 --- a/hai-service/pom.xml +++ b/hai-service/pom.xml @@ -312,6 +312,11 @@ wechatpay-apache-httpclient 0.2.2 + + com.sun.jersey + jersey-client + 1.16 + diff --git a/hai-service/src/main/java/com/hai/common/utils/UnionUtils.java b/hai-service/src/main/java/com/hai/common/utils/UnionUtils.java new file mode 100644 index 00000000..71358575 --- /dev/null +++ b/hai-service/src/main/java/com/hai/common/utils/UnionUtils.java @@ -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 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 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 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 param){ + StringBuilder result = new StringBuilder(); + Collection keySet = param.keySet(); + List list = new ArrayList(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 params){ + StringBuilder sb = new StringBuilder(); + // 将参数以参数名的字典升序排序 + Map sortParams = new TreeMap(params); + // 遍历排序的字典,并拼接"key=value"格式 + for (Map.Entry 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 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; + } + +} diff --git a/hai-service/src/main/java/com/hai/config/UnionUserConfig.java b/hai-service/src/main/java/com/hai/config/UnionUserConfig.java index 095c095b..1ebe4997 100644 --- a/hai-service/src/main/java/com/hai/config/UnionUserConfig.java +++ b/hai-service/src/main/java/com/hai/config/UnionUserConfig.java @@ -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 paramMap = new HashMap<>(); + public String getBackendToken() { + Object token = redisUtil.get("UNION_BACKEND_TOKEN"); + if (token != null) { + return token.toString(); + } + Map 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 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 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 param) { + private static String paramSort(final Map param) { Set 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 data){ + private static String generateSign(Map 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"); diff --git a/hai-service/src/main/java/com/hai/dao/HighUserMapper.java b/hai-service/src/main/java/com/hai/dao/HighUserMapper.java index 69ace2cb..200fd730 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserMapper.java @@ -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},", diff --git a/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java index c10a1cd1..db1ab51f 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java @@ -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}"); } diff --git a/hai-service/src/main/java/com/hai/entity/HighUser.java b/hai-service/src/main/java/com/hai/entity/HighUser.java index 4caf07d5..4703c460 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUser.java +++ b/hai-service/src/main/java/com/hai/entity/HighUser.java @@ -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); diff --git a/hai-service/src/main/java/com/hai/entity/HighUserExample.java b/hai-service/src/main/java/com/hai/entity/HighUserExample.java index 0601560d..62383012 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserExample.java @@ -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 values) { + addCriterion("union_open_id in", values, "unionOpenId"); + return (Criteria) this; + } + + public Criteria andUnionOpenIdNotIn(List 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 values) { + addCriterion("union_union_id in", values, "unionUnionId"); + return (Criteria) this; + } + + public Criteria andUnionUnionIdNotIn(List 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;