| @@ -179,7 +179,7 @@ public class WxCUserController extends BaseController { | |||
| } | |||
| isAddCredit = true; | |||
| wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setId(idWorker.nextId()); | |||
| wxCUserBasicInfo.setTenantId("," + wxCUser.getTenantId() + ","); | |||
| wxCUserBasicInfo.setFinalTenantId(wxCUser.getFinalTenantId()); | |||
| wxCUserBasicInfo.setPhone(wxCUserFromBDto.getPhone()); | |||
| @@ -195,10 +195,6 @@ public class WxCUserController extends BaseController { | |||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getAddress())) { | |||
| wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); | |||
| } | |||
| wxCUserBasicInfo.setLoginCount(1); | |||
| wxCUserBasicInfo.setActiveTime(new Date()); | |||
| wxCUserBasicInfo.setCreateDate(new Date()); | |||
| wxCUserBasicInfo.setUpdateDate(new Date()); | |||
| wxCUserBasicInfoService.save(wxCUserBasicInfo); | |||
| } | |||
| @@ -212,7 +208,6 @@ public class WxCUserController extends BaseController { | |||
| } | |||
| isAddCredit = true; | |||
| wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setId(idWorker.nextId()); | |||
| wxCUserBasicInfo.setTenantId("," + bUser.getTenantId() + ","); | |||
| wxCUserBasicInfo.setFinalTenantId(bUser.getFinalTenantId()); | |||
| wxCUserBasicInfo.setPhone(wxCUserFromBDto.getPhone()); | |||
| @@ -228,10 +223,6 @@ public class WxCUserController extends BaseController { | |||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getAddress())) { | |||
| wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); | |||
| } | |||
| wxCUserBasicInfo.setLoginCount(1); | |||
| wxCUserBasicInfo.setActiveTime(new Date()); | |||
| wxCUserBasicInfo.setCreateDate(new Date()); | |||
| wxCUserBasicInfo.setUpdateDate(new Date()); | |||
| wxCUserBasicInfoService.save(wxCUserBasicInfo); | |||
| wxCUser = new WxCUser(); | |||
| @@ -257,20 +257,13 @@ public class BaseController { | |||
| removeCacheMember(basicInfo.getId()); | |||
| return byId.getId(); | |||
| } else { | |||
| Date cur = new Date(); | |||
| basicInfo = new WxCUserBasicInfo(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| basicInfo.setId(idWorker.nextId()); | |||
| basicInfo.setTenantId("," + tenantEntity.getTenantId() + ","); | |||
| basicInfo.setFinalTenantId(tenantEntity.getFinalTenantId()); | |||
| basicInfo.setPhone(userPhone); | |||
| basicInfo.setNickName(userName); | |||
| basicInfo.setAvatarUrl(avatarUrl); | |||
| basicInfo.setSex(sex); | |||
| basicInfo.setLoginCount(1); | |||
| basicInfo.setActiveTime(cur); | |||
| basicInfo.setCreateDate(cur); | |||
| basicInfo.setUpdateDate(cur); | |||
| wxCUserBasicInfoService.save(basicInfo); | |||
| removeCacheMember(basicInfo.getId()); | |||
| return basicInfo.getId(); | |||
| @@ -0,0 +1,40 @@ | |||
| package com.iformall.controller.callback; | |||
| import com.iformall.controller.base.BaseController; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.ResponseBody; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/wxBusiness") | |||
| public class WxBusinessOrderController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| /** | |||
| * | |||
| * @return 微信商圈支付结果通知 | |||
| */ | |||
| @PostMapping(value = "/order") | |||
| @ResponseBody | |||
| public Map<String,String> createOrder(HttpServletRequest request){ | |||
| logger.info("[" +getIpAddr() + "]微信商圈支付结果通知"); | |||
| Map<String,String> resultMap = new HashMap<>(); | |||
| resultMap.put("code","SUCCESS"); | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| } | |||
| } | |||
| @@ -1,14 +1,20 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.utils.HttpUtil; | |||
| import com.iformall.utils.sign.SignUtils; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.Date; | |||
| @@ -22,22 +28,39 @@ public class UserBasicInfoController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| /** | |||
| * 用户注册 | |||
| * | |||
| * @param | |||
| * @return | |||
| */ | |||
| @PostMapping("/register") | |||
| @ApiOperation(value = "用户注册", notes = "") | |||
| @ApiOperation(value = "会员", notes = "") | |||
| public ResultData userRegister(@RequestBody Map<String,Object> map) { | |||
| logger.info("UserBasicInfoController >>>>>>>>>>>>>>>>>>>>>>>>>"+map.toString()); | |||
| // logger.info("UserBasicInfoController >>>>>>>>phone >>>>>>>>>>>>>>>>>"+phone); | |||
| return new ResultData(); | |||
| logger.info("UserBasicInfoController >>>>>>>>>>>> userRegister >>>>>>>>>>>>>"+map.toString()); | |||
| String phone = (String) map.get("phone"); | |||
| if(StringUtils.isBlank(phone)){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"手机号不能为空"); | |||
| } | |||
| if(!phone.matches("^1[0-9]{10}$")){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"手机号格式不正确"); | |||
| } | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.registerByPhone(tenantEntity, phone); | |||
| return new ResultData(wxCUserBasicInfo); | |||
| } | |||
| public static void main(String[] args) { | |||
| String appId = "CP6nwHvZ"; | |||
| @@ -47,11 +70,11 @@ public class UserBasicInfoController extends BaseController { | |||
| Map<String,String> headMap = new HashMap<>(); | |||
| headMap.put("appkey",appId+"&"+appKey); | |||
| Map<String,String> paramMap = new HashMap<>(); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| String timeStamp = Long.toString(new Date().getTime()); | |||
| System.out.println("timeStamp="+timeStamp); | |||
| paramMap.put("timeStamp",timeStamp);//当前时间戳 | |||
| paramMap.put("phone","17600293031"); | |||
| paramMap.put("phone","17600000000"); | |||
| paramMap.put("userName","昵称"); | |||
| paramMap.put("userSex","1"); | |||
| @@ -0,0 +1,77 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.utils.HttpUtil; | |||
| import com.iformall.utils.sign.SignUtils; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("api/userBusiness") | |||
| @Api(description = "会员交易相关接口") | |||
| public class UserBusinessOrderController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| /** | |||
| * | |||
| * @param | |||
| * @return | |||
| */ | |||
| @PostMapping("/order") | |||
| @ApiOperation(value = "商圈订单", notes = "") | |||
| public ResultData createOrder(@RequestBody Map<String,Object> map) { | |||
| logger.info("UserBusinessOrderController >>>>>>>>>>>> createOrder >>>>>>>>>>>>>"+map.toString()); | |||
| return new ResultData(); | |||
| } | |||
| /** | |||
| * | |||
| * @param | |||
| * @return | |||
| */ | |||
| @PostMapping("/orderRefund") | |||
| @ApiOperation(value = "取消订单", notes = "") | |||
| public ResultData orderRefund(@RequestBody Map<String,Object> map) { | |||
| logger.info("UserBusinessOrderController >>>>>>>>>>>> orderRefund >>>>>>>>>>>>>"+map.toString()); | |||
| return new ResultData(); | |||
| } | |||
| /** | |||
| * | |||
| * @param | |||
| * @return | |||
| */ | |||
| @PostMapping("/pointDeduction") | |||
| @ApiOperation(value = "积分抵扣", notes = "") | |||
| public ResultData pointDeduction(@RequestBody Map<String,Object> map) { | |||
| logger.info("UserBusinessOrderController >>>>>>>>>>>> pointDeduction >>>>>>>>>>>>>"+map.toString()); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -1,9 +1,6 @@ | |||
| package com.iformall.interceptor; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.alibaba.fastjson.TypeReference; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxThirdPartyApi; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -21,15 +18,8 @@ import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Component; | |||
| import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||
| import javax.servlet.ServletException; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStreamReader; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.net.URLDecoder; | |||
| import java.net.URLEncoder; | |||
| import java.util.*; | |||
| /** | |||
| @@ -42,6 +32,8 @@ import java.util.*; | |||
| public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| private final String[] notKeys = {"sign","appId","appKey","signKey"}; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| @@ -73,17 +65,17 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| } | |||
| String body = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | |||
| if(StringUtils.isBlank(body)){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"缺少参数"); | |||
| } | |||
| try{ | |||
| // JSONObject parameterMap = JSON.parseObject(body); | |||
| Map<String, String> parameterMap = JSONObject.parseObject(body, new TypeReference<Map<String, String>>() { | |||
| }); | |||
| String timeStamp = parameterMap.get("timeStamp"); | |||
| Map<String, Object> parameterMap = JSONObject.parseObject(body, Map.class); | |||
| if(parameterMap.isEmpty()){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"参数格式不正确"); | |||
| } | |||
| String timeStamp = (String) parameterMap.get("timeStamp"); | |||
| long timestampDate = Long.valueOf(timeStamp) + 1000*60*5;//五分钟有效 | |||
| long currDate = System.currentTimeMillis(); | |||
| // 请求过期 | |||
| @@ -92,7 +84,13 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| } | |||
| logger.info("sign={}"+signature); | |||
| String signKey = apiConfig.getSignKey();//TODO 根据appId查询密钥,缓存 | |||
| String signKey = apiConfig.getSignKey(); | |||
| for (String key:notKeys) { | |||
| if(parameterMap.containsKey(key)){ | |||
| parameterMap.remove(key); | |||
| } | |||
| } | |||
| String newSignature = SignUtils.getSign(signKey, parameterMap, "MD5"); | |||
| //加密串不匹配 | |||
| if (!signature.equals(newSignature)) { | |||
| @@ -109,91 +107,6 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"参数格式不正确"); | |||
| } | |||
| // Map<String, String> param = StringToMap(body); | |||
| // if(param.isEmpty()){ | |||
| // throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"参数格式不正确"); | |||
| // } | |||
| // | |||
| // String timeStamp = param.get("timeStamp"); | |||
| // long timestampDate = Long.valueOf(timeStamp) + 1000*60*5;//五分钟有效 | |||
| // long currDate = System.currentTimeMillis(); | |||
| // // 请求过期 | |||
| // if (timestampDate < currDate) { | |||
| // throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请求过期"); | |||
| // } | |||
| // String nonceStr = param.get("nonceStr"); | |||
| // //重复调用 | |||
| // Integer cache = RedisCacheUtils.getCacheInteger(redisTemplate, Constant.publicApiNonce+nonceStr); | |||
| // if (null != cache) { | |||
| // throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"重复调用"); | |||
| // } | |||
| // Enumeration<String> paramNames = request.getParameterNames(); | |||
| // Map<String, String> map = new HashMap(); | |||
| // | |||
| // //获取所有的请求参数 | |||
| // while (paramNames.hasMoreElements()) { | |||
| // String paramName = paramNames.nextElement(); | |||
| // String[] paramValues = request.getParameterValues(paramName); | |||
| // | |||
| // if (paramValues.length > 0) { | |||
| // String paramValue = paramValues[0]; | |||
| // if (paramValue.length() != 0 | |||
| // && !"sign".equals(paramName) | |||
| // && !"appId".equals(paramName) | |||
| // && !"appKey".equals(paramName) | |||
| // && !"signKey".equals(paramName)) { | |||
| // map.put(paramName, paramValue); | |||
| // } | |||
| // } | |||
| // } | |||
| // logger.info("sign={}"+signature); | |||
| // String signKey = apiConfig.getSignKey();//TODO 根据appId查询密钥,缓存 | |||
| // String newSignature = SignUtils.getSign(signKey, param, "MD5"); | |||
| // //加密串不匹配 | |||
| // if (!signature.equals(newSignature)) { | |||
| // throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"加密串校验失败"); | |||
| // } | |||
| // Integer cache = RedisCacheUtils.getCacheInteger(redisTemplate, Constant.publicApiNonce+signature); | |||
| // if (null != cache) { | |||
| // throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"重复调用"); | |||
| // } | |||
| // RedisCacheUtils.cache(redisTemplate, Constant.publicApiNonce+signature, 1, 300); | |||
| // return true; | |||
| } | |||
| // private Map<String, String> StringToMap(String body){ | |||
| // Map<String, String> map = new HashMap<String, String>(); | |||
| // String bodyDecode = ""; | |||
| // try { | |||
| // bodyDecode = URLDecoder.decode(body, "utf-8"); | |||
| // } catch (UnsupportedEncodingException e) { | |||
| // e.printStackTrace(); | |||
| // return map; | |||
| // } | |||
| // | |||
| // String[] keyValues = bodyDecode.split("&"); | |||
| // for (String kv:keyValues) { | |||
| // if(StringUtils.isBlank(kv) || !kv.contains("=")){ | |||
| // continue; | |||
| // } | |||
| // String[] key_value = kv.split("="); | |||
| // String key = key_value[0]; | |||
| // if(StringUtils.isNotBlank(key) | |||
| // && !"sign".equals(key) | |||
| // && !"appId".equals(key) | |||
| // && !"appKey".equals(key) | |||
| // && !"signKey".equals(key)){ | |||
| // String value = kv.substring(kv.indexOf('=') + 1, kv.length()); | |||
| // map.put(key_value[0],value); | |||
| // } | |||
| // } | |||
| // return map; | |||
| // } | |||
| } | |||
| @@ -173,5 +173,7 @@ public interface WxCUserBasicInfoService { | |||
| void cuserOldToNew(Long oldCuserId, Long newCuserId,TenantEntity tenantinfo); | |||
| void updateQrCode(WxCUserBasicInfo wxCUserBasicInfo); | |||
| WxCUserBasicInfo registerByPhone(TenantEntity tenantEntity, String phone); | |||
| } | |||
| @@ -638,6 +638,24 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExc | |||
| wxCUserBasicInfoMapper.updateQrCode(record); | |||
| } | |||
| @Override | |||
| public WxCUserBasicInfo registerByPhone(TenantEntity tenantEntity, String phone) { | |||
| if (StringUtils.isBlank(phone)) | |||
| return null; | |||
| WxCUserBasicInfo basicInfo = this.findInfoByPhone(tenantEntity, phone); | |||
| if(basicInfo != null){ | |||
| return basicInfo; | |||
| }else{ | |||
| basicInfo = new WxCUserBasicInfo(); | |||
| basicInfo.setTenantId("," + tenantEntity.getTenantId() + ","); | |||
| basicInfo.setPhone(phone); | |||
| this.save(basicInfo); | |||
| return basicInfo; | |||
| } | |||
| } | |||
| @Override | |||
| public WxCUserBasicInfo getById(Long id,String finalTenantId) { | |||
| return wxCUserBasicInfoMapper.selectById(id,finalTenantId); | |||
| @@ -645,6 +663,13 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExc | |||
| @Override | |||
| public void save(WxCUserBasicInfo record) { | |||
| Date cur = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| record.setLoginCount(1); | |||
| record.setActiveTime(cur); | |||
| record.setCreateDate(cur); | |||
| record.setUpdateDate(cur); | |||
| wxCUserBasicInfoMapper.insert(record); | |||
| } | |||
| @@ -51,7 +51,7 @@ public class WxGooagooServiceImpl implements WxGooagooService { | |||
| if(config == null){ | |||
| return new ResultData(ErrorCode.GOOAGOO_INFO_NOT_FOUND); | |||
| } | |||
| Map<String,String> paramMap = this.getParamMap(config); | |||
| Map<String,Object> paramMap = this.getParamMap(config); | |||
| paramMap.put("lowerMethod",url); | |||
| List<String> sl = new ArrayList<>(); | |||
| sl.add(config.getTpId()); | |||
| @@ -77,9 +77,9 @@ public class WxGooagooServiceImpl implements WxGooagooService { | |||
| } | |||
| } | |||
| private Map<String,String> getParamMap(WxThirdPartyConfig config){ | |||
| private Map<String,Object> getParamMap(WxThirdPartyConfig config){ | |||
| Map<String,String> map = new HashMap<>(); | |||
| Map<String,Object> map = new HashMap<>(); | |||
| map.put("appId",config.getAppId()); | |||
| map.put("appKey",config.getAppKey()); | |||
| map.put("method",method); | |||
| @@ -14,11 +14,11 @@ public class SignUtils { | |||
| public SignUtils() { | |||
| } | |||
| public static String sign(String appSecret, Map<String, String> form) { | |||
| public static String sign(String appSecret, Map<String, Object> form) { | |||
| return getSign(appSecret, form, (String)form.get("signMethod")); | |||
| } | |||
| public static String getSign(String appSecret, Map<String, String> params, String signMethod) { | |||
| public static String getSign(String appSecret, Map<String, Object> params, String signMethod) { | |||
| String[] keys = (String[])params.keySet().toArray(new String[0]); | |||
| Arrays.sort(keys); | |||
| StringBuilder signStr = new StringBuilder(); | |||