| @@ -7,6 +7,7 @@ import com.simple.exception.BizMessageException; | |||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.pay.WxPayment; | import com.simple.pay.WxPayment; | ||||
| import com.simple.utils.IPUtil; | import com.simple.utils.IPUtil; | ||||
| import org.apache.commons.codec.Charsets; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -24,6 +25,7 @@ import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import java.nio.charset.Charset; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -43,6 +45,10 @@ public class WxPayOrderController extends BaseController { | |||||
| }) | }) | ||||
| @RequestMapping(value = "/create", method = RequestMethod.POST) | @RequestMapping(value = "/create", method = RequestMethod.POST) | ||||
| public ResultData _create(WxPayOrder record, HttpServletRequest request) throws Exception { | public ResultData _create(WxPayOrder record, HttpServletRequest request) throws Exception { | ||||
| // 1. get openId by cUserId | |||||
| // 2. check total fee is not null | |||||
| // 3. check body is not null | |||||
| // | |||||
| logger.info("payment wechat, order create, param : " + record.toString()); | logger.info("payment wechat, order create, param : " + record.toString()); | ||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| @@ -66,7 +72,7 @@ public class WxPayOrderController extends BaseController { | |||||
| Map<String, String> paramMap = null; | Map<String, String> paramMap = null; | ||||
| String response; | String response; | ||||
| try { | try { | ||||
| String xml = IOUtils.toString(request.getInputStream()); | |||||
| String xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||||
| paramMap = WxPayment.xmlToMap(xml); | paramMap = WxPayment.xmlToMap(xml); | ||||
| logger.info("payment wxpay, notify, param: " + paramMap.toString() ); | logger.info("payment wxpay, notify, param: " + paramMap.toString() ); | ||||
| response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | ||||
| @@ -3,7 +3,7 @@ | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
| <modelVersion>4.0.0</modelVersion> | <modelVersion>4.0.0</modelVersion> | ||||
| <parent> | |||||
| <parent> | |||||
| <artifactId>mallink</artifactId> | <artifactId>mallink</artifactId> | ||||
| <groupId>com.simple</groupId> | <groupId>com.simple</groupId> | ||||
| <version>1.0</version> | <version>1.0</version> | ||||
| @@ -11,15 +11,27 @@ | |||||
| <artifactId>mallinkCApi</artifactId> | <artifactId>mallinkCApi</artifactId> | ||||
| <dependencies> | |||||
| <properties> | |||||
| <weixin-java-miniapp.version>3.1.0</weixin-java-miniapp.version> | |||||
| </properties> | |||||
| <dependencies> | |||||
| <dependency> | |||||
| <groupId>com.github.binarywang</groupId> | |||||
| <artifactId>weixin-java-miniapp</artifactId> | |||||
| <version>${weixin-java-miniapp.version}</version> | |||||
| </dependency> | |||||
| <dependency> | <dependency> | ||||
| <groupId>com.simple</groupId> | <groupId>com.simple</groupId> | ||||
| <artifactId>mallinkService</artifactId> | <artifactId>mallinkService</artifactId> | ||||
| <version>1.0</version> | <version>1.0</version> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>com.github.binarywang</groupId> | |||||
| <artifactId>weixin-java-miniapp</artifactId> | |||||
| <version>3.0.0</version> | |||||
| </dependency> | |||||
| </dependencies> | </dependencies> | ||||
| <build> | |||||
| <build> | |||||
| <plugins> | <plugins> | ||||
| <plugin> | <plugin> | ||||
| <groupId>org.springframework.boot</groupId> | <groupId>org.springframework.boot</groupId> | ||||
| @@ -24,6 +24,7 @@ import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import java.nio.charset.Charset; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -66,7 +67,7 @@ public class WxPayOrderController extends BaseController { | |||||
| Map<String, String> paramMap = null; | Map<String, String> paramMap = null; | ||||
| String response; | String response; | ||||
| try { | try { | ||||
| String xml = IOUtils.toString(request.getInputStream()); | |||||
| String xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||||
| paramMap = WxPayment.xmlToMap(xml); | paramMap = WxPayment.xmlToMap(xml); | ||||
| logger.info("payment wxpay, notify, param: " + paramMap.toString() ); | logger.info("payment wxpay, notify, param: " + paramMap.toString() ); | ||||
| response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | ||||
| @@ -0,0 +1,300 @@ | |||||
| package com.simple.controller; | |||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | |||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.service.WxCUserService; | |||||
| import com.simple.utils.IPUtil; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import me.chanjar.weixin.common.exception.WxErrorException; | |||||
| 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 org.springframework.web.context.request.RequestContextHolder; | |||||
| import org.springframework.web.context.request.ServletRequestAttributes; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/api/user") | |||||
| public class WxUserGrantController { | |||||
| private final static Logger logger = LoggerFactory.getLogger(WxUserGrantController.class); | |||||
| @Autowired | |||||
| private WxMaService wxService; | |||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| /** | |||||
| * 用户登录 | |||||
| * @param map | |||||
| * @return | |||||
| */ | |||||
| @PostMapping("/login") | |||||
| @ApiOperation(value="用户登录", notes="{\"code\":\"string\",\"scene\":\"string\",\"sceneAddress\":\"string\"}") | |||||
| public ResultData userLogin(@RequestBody Map<String, String> map) { | |||||
| logger.debug(map.toString()); | |||||
| String code = map.get("code"); | |||||
| String scene = map.get("scene"); | |||||
| String sceneAddress = map.get("sceneAddress"); | |||||
| //登录凭证不能为空 | |||||
| if (StringUtils.isBlank(code)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "code不能为空"); | |||||
| } | |||||
| String session_key = null; | |||||
| String openId = null; | |||||
| HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| try { | |||||
| WxMaJscode2SessionResult session = wxService.jsCode2SessionInfo(code); | |||||
| //获取会话密钥(session_key) | |||||
| session_key = session.getSessionKey(); | |||||
| openId = session.getOpenid(); | |||||
| logger.info("session_key: " + session_key); | |||||
| logger.info("openId: " + openId); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| return new ResultData(); | |||||
| } | |||||
| /* | |||||
| try { | |||||
| WxUserEntity user1 = wxCUserService.getById(); | |||||
| if (user1 != null) { | |||||
| user1.setSessionKey(session_key); | |||||
| wxUserService.update(user1); | |||||
| } else { | |||||
| WxUserEntity user = new WxUserEntity(); | |||||
| user.setRegisterip(ipaddress); | |||||
| if (user.getScene() == null) | |||||
| user.setScene(scene); | |||||
| if (user.getSceneAddress() == null) | |||||
| user.setSceneAddress(sceneAddress); | |||||
| if (scene != null) { | |||||
| user.setQrcodesource(scene); | |||||
| } else { | |||||
| user.setQrcodesource(sceneAddress); | |||||
| } | |||||
| user.setOpenid(openId); | |||||
| user.setSessionKey(session_key); | |||||
| wxUserService.save(user); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| */ | |||||
| return new ResultData(); | |||||
| } | |||||
| /** | |||||
| * 获取用户的昵称等信息 | |||||
| * @param map | |||||
| * @return | |||||
| */ | |||||
| @PostMapping("/getUserInfo") | |||||
| @ApiOperation(value="授权后获取用户的昵称,unionId等信息", notes="{\"encryptedData\":\"string\",\"iv\":\"string\",\"openId\":\"string\"}") | |||||
| public ResultData getUserInfo(@RequestBody Map<String, String> map) { | |||||
| logger.debug(map.toString()); | |||||
| String openId = map.get("openId"); | |||||
| String encryptedData = map.get("encryptedData"); | |||||
| String iv = map.get("iv"); | |||||
| if (StringUtils.isBlank(encryptedData)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "encryptedData不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(iv)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "iv不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(openId)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "openId不能为空"); | |||||
| } | |||||
| WxCUser user = null; | |||||
| /* | |||||
| try { | |||||
| //user = wxCUserService.queryObjectByOpenId(openId); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| if (user != null) { | |||||
| logger.debug(user.toString()); | |||||
| String session_key = user.getSessionKey(); | |||||
| try { | |||||
| // 解密用户信息 | |||||
| WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo(session_key, encryptedData, iv); | |||||
| if (userInfo != null) { | |||||
| logger.debug(userInfo.toString()); | |||||
| user.setUnionid(userInfo.getUnionId()); | |||||
| user.setNickname(userInfo.getNickName()); | |||||
| user.setGender(Integer.parseInt(userInfo.getGender())); | |||||
| user.setAvatarurl(userInfo.getAvatarUrl()); | |||||
| user.setProvince(userInfo.getProvince()); | |||||
| user.setCity(userInfo.getCity()); | |||||
| user.setLanguage(userInfo.getLanguage()); | |||||
| wxUserService.update(user); | |||||
| r.put("openId", user.getOpenid()); | |||||
| r.put("unionId", user.getUnionid()); | |||||
| r.put("msg", "获取用户信息成功!"); | |||||
| return r; | |||||
| } else { | |||||
| return R.code(22, "解密失败"); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| } else { | |||||
| return R.code(20, "用户信息未找到"); | |||||
| } | |||||
| */ | |||||
| return new ResultData(); | |||||
| } | |||||
| /** | |||||
| * 授权后获取用户的手机号等信息 | |||||
| * @param map | |||||
| * @return | |||||
| */ | |||||
| /* | |||||
| @PostMapping("/getUserPhone") | |||||
| @ApiOperation(value = "授权后获取用户的手机号", notes="{\"encryptedData\":\"string\",\"iv\":\"\",\"openId\":\"\"}") | |||||
| public new ResultData getUserPhone(@RequestBody Map<String, String> map) { | |||||
| logger.debug(map.toString()); | |||||
| R r = new R(); | |||||
| String encryptedData = map.get("encryptedData"); | |||||
| String iv = map.get("iv"); | |||||
| String openId = map.get("openId"); | |||||
| //登录凭证不能为空 | |||||
| if (StringUtils.isBlank(encryptedData)) { | |||||
| return R.code(1, "encryptedData 不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(iv)) { | |||||
| return R.code(2, "iv 不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(openId)) { | |||||
| return R.code(3, "openId 不能为空"); | |||||
| } | |||||
| WxUserEntity user = null; | |||||
| try { | |||||
| user = wxUserService.queryObjectByOpenId(openId); | |||||
| } catch (Exception e) { | |||||
| this.logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| if (user != null) { | |||||
| logger.debug(user.toString()); | |||||
| String session_key = user.getSessionKey(); | |||||
| try { | |||||
| // 解密 | |||||
| WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo(session_key, encryptedData, iv); | |||||
| if (null != phoneNoInfo) { | |||||
| logger.debug(phoneNoInfo.toString()); | |||||
| user.setPhone(phoneNoInfo.getPhoneNumber()); | |||||
| user.setPurephone(phoneNoInfo.getPurePhoneNumber()); | |||||
| user.setCountrycode(phoneNoInfo.getCountryCode()); | |||||
| wxUserService.update(user); | |||||
| r.put("msg","授权手机成功!"); | |||||
| r.put("phone",phoneNoInfo.getPhoneNumber()); | |||||
| return r; | |||||
| } else { | |||||
| return R.code(22, "解密失败"); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| this.logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| } else { | |||||
| return R.code(20, "用户信息未找到"); | |||||
| } | |||||
| } | |||||
| */ | |||||
| /** | |||||
| * 判断是否是老用户 | |||||
| * @param map | |||||
| * @return | |||||
| */ | |||||
| /* | |||||
| @PostMapping("/isOldUser") | |||||
| @ApiOperation(value = "判断是否是老用户", notes="{\"openId\":\"\"}") | |||||
| public R isOldUser(@RequestBody Map<String, String> map) { | |||||
| logger.debug(map.toString()); | |||||
| String openId = map.get("openId"); | |||||
| //登录凭证不能为空 | |||||
| if (StringUtils.isBlank(openId)) { | |||||
| return R.code(1, "openId 不能为空"); | |||||
| } | |||||
| R r = new R(); | |||||
| try { | |||||
| WxUserEntity user1 = wxUserService.queryObjectByOpenId(openId); | |||||
| if (user1 != null) { | |||||
| logger.info(user1.toString()); | |||||
| // nickname, unionId is null, 31 | |||||
| // phone is null, 29, | |||||
| // idcard,name is null, 30 | |||||
| // all have, 32 | |||||
| if (!StringUtils.isBlank(user1.getUnionid())) { | |||||
| r.put("unionId", user1.getUnionid()); | |||||
| } | |||||
| if (!StringUtils.isBlank(user1.getPhone())) { | |||||
| r.put("phone", user1.getPhone()); | |||||
| } | |||||
| if (!StringUtils.isBlank(user1.getVipno())) { | |||||
| r.put("memberId", user1.getVipno()); | |||||
| } | |||||
| if (StringUtils.isBlank(user1.getUnionid())) { | |||||
| r.put("type", 31).put("code", 31); | |||||
| r.put("msg", "是新用户,请跳转到用户授权页!"); | |||||
| logger.warn("是新用户,跳转到用户授权页!"); | |||||
| return r; | |||||
| } | |||||
| if (StringUtils.isBlank(user1.getPhone())) { | |||||
| r.put("type", 29).put("code", 29); | |||||
| r.put("msg", "是新用户,跳转到授权手机号页!"); | |||||
| logger.warn("是新用户,跳转到授权手机号页!"); | |||||
| return r; | |||||
| } | |||||
| if (StringUtils.isBlank(user1.getVipno())) { | |||||
| r.put("type",28).put("code", 28); | |||||
| r.put("msg", "是新用户,跳转到注册华联会员!"); | |||||
| logger.warn("是新用户,跳转到注册华联会员!"); | |||||
| return r; | |||||
| } | |||||
| r.put("type",32).put("code", 32); | |||||
| r.put("msg", "老用户"); | |||||
| return r; | |||||
| } else { | |||||
| r.put("type", 31).put("code", 31); | |||||
| r.put("msg", "是新用户,请跳转到用户授权页!"); | |||||
| logger.warn("是新用户,跳转到用户授权页!"); | |||||
| return r; | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| }*/ | |||||
| } | |||||
| @@ -27,8 +27,8 @@ public enum ErrorCode{ | |||||
| EXTEND_JSON_ERROR(1012, "JSON格式异常"), | EXTEND_JSON_ERROR(1012, "JSON格式异常"), | ||||
| REPEAT_SUBMIT_EXCEPTION(1013, "请勿重复操作"), | REPEAT_SUBMIT_EXCEPTION(1013, "请勿重复操作"), | ||||
| LOGIN_DENIED(1013, "登录失败"), | |||||
| TOKEN_INVALID(1014, "TOKEN无效"), | |||||
| LOGIN_DENIED(1014, "登录失败"), | |||||
| TOKEN_INVALID(1015, "TOKEN无效"), | |||||
| /** | /** | ||||
| @@ -42,19 +42,29 @@ public enum ErrorCode{ | |||||
| LOGIN_USER_OR_PWD_ERROR(2002, "用户名或密码错误"), | LOGIN_USER_OR_PWD_ERROR(2002, "用户名或密码错误"), | ||||
| USER_IS_LOCKED(2003, "用户已经被锁定不能登录,请与管理员联系"), | USER_IS_LOCKED(2003, "用户已经被锁定不能登录,请与管理员联系"), | ||||
| /** | |||||
| * 车流 2050 | |||||
| */ | |||||
| /** | /** | ||||
| * 订单 | * 订单 | ||||
| */ | */ | ||||
| REMAIN_IS_EMPTY(12000, "库存不足"), | |||||
| ORDER_IS_FAIL(12001, "订单创建失败"), | |||||
| ORDER_IS_NOT_FIND(12002, "订单不存在"), | |||||
| ORDER_IS_NOT_PAY(12003, "订单已不能进行支付"), | |||||
| PAYORDER_ERROR(12004, "支付订单异常"), | |||||
| PAYORDER_NOTIFY_CHECK_SIGN_ERROR(12005 , "验签失败"); | |||||
| REMAIN_IS_EMPTY(3000, "库存不足"), | |||||
| ORDER_IS_FAIL(3001, "订单创建失败"), | |||||
| ORDER_IS_NOT_FIND(3002, "订单不存在"), | |||||
| ORDER_IS_NOT_PAY(3003, "订单已不能进行支付"), | |||||
| /** | |||||
| * 微信 | |||||
| */ | |||||
| /** | /** | ||||
| * 支付 | * 支付 | ||||
| */ | */ | ||||
| PAYORDER_ERROR(12004, "支付订单异常"), | |||||
| PAYORDER_NOTIFY_CHECK_SIGN_ERROR(12005 , "验签失败"); | |||||
| @@ -0,0 +1,45 @@ | |||||
| package com.simple.domain.vo; | |||||
| import java.io.Serializable; | |||||
| public class CouponListReq implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| /*租户ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||||
| private String tenantId; | |||||
| /*卡券ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡券ID",name="couponId") | |||||
| private Long couponId; | |||||
| /*商户ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId") | |||||
| private Long merchantId; | |||||
| /*业态**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="业态",name="businessId") | |||||
| private Long businessId; | |||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(String _tenantId) { | |||||
| tenantId = _tenantId; | |||||
| } | |||||
| public Long getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(Long _couponId) { | |||||
| couponId = _couponId; | |||||
| } | |||||
| public Long getMerchantId() { | |||||
| return merchantId; | |||||
| } | |||||
| public void setMerchantId(Long _merchantId) { | |||||
| merchantId = _merchantId; | |||||
| } | |||||
| public Long getBusinessId() { | |||||
| return businessId; | |||||
| } | |||||
| public void setBusinessId(Long businessId) { | |||||
| this.businessId = businessId; | |||||
| } | |||||
| } | |||||
| @@ -51,11 +51,12 @@ public class OrderVo implements Serializable { | |||||
| public void setMerchantId(Long _merchantId) { | public void setMerchantId(Long _merchantId) { | ||||
| merchantId = _merchantId; | merchantId = _merchantId; | ||||
| } | } | ||||
| public Long getCUserId() { | |||||
| public Long getcUserId() { | |||||
| return cUserId; | return cUserId; | ||||
| } | } | ||||
| public void setCUserId(Long _cUserId) { | |||||
| cUserId = _cUserId; | |||||
| public void setcUserId(Long cUserId) { | |||||
| this.cUserId = cUserId; | |||||
| } | } | ||||
| public Integer getStatus() { | public Integer getStatus() { | ||||
| @@ -2,14 +2,13 @@ package com.simple.mapper; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.simple.common.CommonMapper; | import com.simple.common.CommonMapper; | ||||
| import com.simple.domain.vo.CouponListReq; | |||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| public interface WxCouponMapper extends CommonMapper<WxCoupon, String> { | public interface WxCouponMapper extends CommonMapper<WxCoupon, String> { | ||||
| List<WxCoupon> findList(WxCoupon wxCoupon); | List<WxCoupon> findList(WxCoupon wxCoupon); | ||||
| @@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils; | |||||
| import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
| import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
| import java.nio.charset.Charset; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Map.Entry; | import java.util.Map.Entry; | ||||
| @@ -289,7 +290,7 @@ public class WxPayment { | |||||
| * 编码错误 | * 编码错误 | ||||
| */ | */ | ||||
| public static String urlEncode(String src) throws UnsupportedEncodingException { | public static String urlEncode(String src) throws UnsupportedEncodingException { | ||||
| return URLEncoder.encode(src, Charsets.UTF_8.name()).replace("+", "%20"); | |||||
| return URLEncoder.encode(src, Charset.forName("UTF-8").name()).replace("+", "%20"); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -1,30 +1,31 @@ | |||||
| package com.simple.service; | package com.simple.service; | ||||
| import java.util.*; | import java.util.*; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| public interface WxCUserService { | public interface WxCUserService { | ||||
| /** | |||||
| /** | |||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| * @param offset | |||||
| * @param limit | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<WxCUser> listAsPage(WxCUser record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| PageInfo<WxCUser> listAsPage(WxCUser record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | * 根据Id获得实体 | ||||
| * | * | ||||
| * @param id | * @param id | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| WxCUser getById(Long id); | WxCUser getById(Long id); | ||||
| /** | |||||
| /** | |||||
| * 保存或更新实体 | * 保存或更新实体 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| @@ -37,12 +38,6 @@ public interface WxCUserService { | |||||
| * @param id | * @param id | ||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| } | } | ||||
| @@ -3,6 +3,7 @@ package com.simple.service; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| import com.simple.domain.vo.CouponListReq; | |||||
| public interface WxCouponService { | public interface WxCouponService { | ||||
| @@ -10,8 +11,8 @@ public interface WxCouponService { | |||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| * @param offset | |||||
| * @param limit | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<WxCoupon> listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize); | PageInfo<WxCoupon> listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize); | ||||
| @@ -4,6 +4,7 @@ import java.util.*; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| import com.simple.domain.vo.CouponListReq; | |||||
| import com.simple.mapper.WxCouponMapper; | import com.simple.mapper.WxCouponMapper; | ||||
| import com.simple.service.WxCouponService; | import com.simple.service.WxCouponService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -2,6 +2,9 @@ package com.simple.service.impl; | |||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.util.*; | import java.util.*; | ||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| @@ -45,6 +48,22 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| @Autowired | @Autowired | ||||
| WxOrderService wxOrderService; | WxOrderService wxOrderService; | ||||
| JSONObject errorMap = JSON.parseObject("{\"NOAUTH\":{\"detail\":\"商户无此接口权限\",\"reason\":\"商户未开通此接口权限\",\"resolution\":\"请商户前往申请此接口权限\"}," + | |||||
| "\"NOTENOUGH\":{\"detail\":\"余额不足\",\"reason\":\"用户帐号余额不足\",\"resolution\":\"用户帐号余额不足,请用户充值或更换支付卡后再支付\"}," + | |||||
| "\"ORDERPAID\":{\"detail\":\"商户订单已支付\",\"reason\":\"商户订单已支付,无需重复操作\",\"resolution\":\"商户订单已支付,无需更多操作\"}," + | |||||
| "\"ORDERCLOSED\":{\"detail\":\"订单已关闭\",\"reason\":\"当前订单已关闭,无法支付\",\"resolution\":\"当前订单已关闭,请重新下单\"}," + | |||||
| "\"SYSTEMERROR\":{\"detail\":\"系统错误\t\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," + | |||||
| "\"APPID_NOT_EXIST\":{\"detail\":\"APPID不存在\",\"reason\":\"参数中缺少APPID\",\"resolution\":\"请检查APPID是否正确\"}," + | |||||
| "\"MCHID_NOT_EXIST\":{\"detail\":\"MCHID不存在\",\"reason\":\"参数中缺少MCHID\",\"resolution\":\"请检查MCHID是否正确\"}," + | |||||
| "\"APPID_MCHID_NOT_MATCH\":{\"detail\":\"appid和mch_id不匹配\",\"reason\":\"appid和mch_id不匹配\",\"resolution\":\"请确认appid和mch_id是否匹配\"}," + | |||||
| "\"LACK_PARAMS\":{\"detail\":\"缺少参数\t\",\"reason\":\"缺少必要的请求参数\",\"resolution\":\"请检查参数是否齐全\"}," + | |||||
| "\"OUT_TRADE_NO_USED\":{\"detail\":\"商户订单号重复\",\"reason\":\"同一笔交易不能多次提交\",\"resolution\":\"请核实商户订单号是否重复提交\"}," + | |||||
| "\"SIGNERROR\":{\"detail\":\"签名错误\",\"reason\":\"参数签名结果不正确\",\"resolution\":\"请检查签名参数和方法是否都符合签名算法要求\"}," + | |||||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"resolution\":\"请检查XML参数格式是否正确\"}," + | |||||
| "\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + | |||||
| "\"POST_DATA_EMPTY\":{\"detail\":\"post数据为空\",\"reason\":\"post数据不能为空\",\"resolution\":\"请检查post数据是否为空\"}," + | |||||
| "\"NOT_UTF8\":{\"detail\":\"编码格式错误\",\"reason\":\"未使用指定编码格式\",\"resolution\":\"请使用UTF-8编码格式\"}}"); | |||||
| @Override | @Override | ||||
| public ResultData createPayOrder(WxPayOrder record, EnumPayWay payWay) { | public ResultData createPayOrder(WxPayOrder record, EnumPayWay payWay) { | ||||
| String partnerKey = null; | String partnerKey = null; | ||||
| @@ -78,45 +97,49 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | ||||
| record.setPayOrderStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); | record.setPayOrderStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); | ||||
| wxPayOrderMapper.insertSelective(record); | |||||
| // 统一下单 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| //wxPayOrderP.setAppid(wechatAppId); | |||||
| //wxPayOrderP.setMch_id(wechatMchId); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| //wxPayOrderP.setBody(body); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| BigDecimal llp = order.getPayment().multiply(new BigDecimal(100)); | |||||
| wxPayOrderP.setTotal_fee(llp.intValue()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| //wxPayOrderP.setNotify_url(wxpayNotifyUrl); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.APP.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime)); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime + 15 * 60)); // 15分钟结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), partnerKey)); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, wxPayOrder:" + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| if ("SUCCESS".equals(returnMap.get("result_code"))) { | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = new HashMap<>(); | |||||
| sighMap.put("appid", returnMap.get("appid")); | |||||
| sighMap.put("partnerid", returnMap.get("mch_id")); | |||||
| sighMap.put("prepayid", returnMap.get("prepay_id")); | |||||
| sighMap.put("package", "Sign=WXPay"); | |||||
| sighMap.put("noncestr", noncestr); | |||||
| sighMap.put("timestamp", timestamp); | |||||
| String signAgent = WxPayment.createSign(sighMap, partnerKey); | |||||
| returnMap.put("timestamp", timestamp); | |||||
| returnMap.put("nonce_str", noncestr); | |||||
| returnMap.put("package", "Sign=WXPay"); | |||||
| returnMap.put("sign", signAgent); | |||||
| return new ResultData(200, "创建支付订单成功", returnMap); | |||||
| int sqlRow = wxPayOrderMapper.insertSelective(record); | |||||
| if(sqlRow == 1) { | |||||
| // 统一下单 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| //wxPayOrderP.setAppid(wechatAppId); | |||||
| //wxPayOrderP.setMch_id(wechatMchId); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| //wxPayOrderP.setBody(body); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| BigDecimal llp = order.getPayment().multiply(new BigDecimal(100)); | |||||
| wxPayOrderP.setTotal_fee(llp.intValue()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| //wxPayOrderP.setNotify_url(wxpayNotifyUrl); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.APP.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime)); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime + 15 * 60)); // 15分钟结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), partnerKey)); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, wxPayOrder:" + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = new HashMap<>(); | |||||
| sighMap.put("appId", returnMap.get("appid")); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id="+prepay_id); | |||||
| String signAgent = WxPayment.createSign(sighMap, partnerKey); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id="+prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| return new ResultData(200, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| JSONObject errObj = errorMap.getJSONObject(result_no); | |||||
| return new ResultData(ErrorCode.PAYORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | |||||
| } | |||||
| } | } | ||||
| return new ResultData(record); | |||||
| return new ResultData(); | |||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAYORDER_ERROR); | throw new MallinkException(ErrorCode.PAYORDER_ERROR); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -27,6 +27,7 @@ import javax.net.ssl.SSLContext; | |||||
| import java.io.*; | import java.io.*; | ||||
| import java.net.URI; | import java.net.URI; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.nio.charset.Charset; | |||||
| import java.security.KeyStore; | import java.security.KeyStore; | ||||
| import java.security.SecureRandom; | import java.security.SecureRandom; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| @@ -239,11 +240,11 @@ public class HttpUtil { | |||||
| conn.connect(); | conn.connect(); | ||||
| out = conn.getOutputStream(); | out = conn.getOutputStream(); | ||||
| out.write(data.getBytes(Charsets.UTF_8)); | |||||
| out.write(data.getBytes(Charset.forName("UTF-8"))); | |||||
| out.flush(); | out.flush(); | ||||
| inputStream = conn.getInputStream(); | inputStream = conn.getInputStream(); | ||||
| reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.UTF_8)); | |||||
| reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); | |||||
| StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
| String line = null; | String line = null; | ||||
| while ((line = reader.readLine()) != null) { | while ((line = reader.readLine()) != null) { | ||||