| @@ -1,14 +1,20 @@ | |||||
| package com.simple.config; | package com.simple.config; | ||||
| import com.alibaba.fastjson.serializer.SerializeConfig; | |||||
| import com.alibaba.fastjson.serializer.ToStringSerializer; | |||||
| import com.alibaba.fastjson.support.config.FastJsonConfig; | |||||
| import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | import com.simple.interceptor.AuthorizationInterceptor; | ||||
| import com.simple.resolver.LoginUserHandlerMethodArgumentResolver; | import com.simple.resolver.LoginUserHandlerMethodArgumentResolver; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.http.converter.HttpMessageConverter; | |||||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||||
| import java.math.BigInteger; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| @@ -44,4 +50,19 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { | |||||
| //registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/"); | //registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/"); | ||||
| } | } | ||||
| @Override | |||||
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | |||||
| FastJsonHttpMessageConverter fastConverter = | |||||
| new FastJsonHttpMessageConverter(); | |||||
| FastJsonConfig fastJsonConfig = new FastJsonConfig(); | |||||
| SerializeConfig serializeConfig = SerializeConfig.globalInstance; | |||||
| serializeConfig.put(BigInteger.class, ToStringSerializer.instance); | |||||
| serializeConfig.put(Long.class, ToStringSerializer.instance); | |||||
| serializeConfig.put(Long.TYPE, ToStringSerializer.instance); | |||||
| fastJsonConfig.setSerializeConfig(serializeConfig); | |||||
| fastConverter.setFastJsonConfig(fastJsonConfig); | |||||
| converters.add(fastConverter); | |||||
| } | |||||
| } | } | ||||
| @@ -86,4 +86,17 @@ public class BaseController { | |||||
| service.setWxMaConfig(config); | service.setWxMaConfig(config); | ||||
| return service; | return service; | ||||
| } | } | ||||
| public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { | |||||
| WxMaInMemoryConfig config = new WxMaInMemoryConfig(); | |||||
| config.setAppid(appinfo.getAppId()); | |||||
| config.setSecret(appinfo.getSecret()); | |||||
| config.setToken(appinfo.getToken()); | |||||
| config.setAesKey(appinfo.getAesKey()); | |||||
| config.setMsgDataFormat(appinfo.getMsgDataFormat()); | |||||
| WxMaService service = new WxMaServiceImpl(); | |||||
| service.setWxMaConfig(config); | |||||
| return service; | |||||
| } | |||||
| } | } | ||||
| @@ -23,9 +23,9 @@ public class WxCouponController extends BaseController | |||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | private WxCouponService wxCouponService; | ||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | |||||
| @GetMapping("/list") | |||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | ||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | ||||
| @@ -58,14 +58,14 @@ public class WxCouponController extends BaseController | |||||
| wxCouponService.deleteById(id); | wxCouponService.deleteById(id); | ||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | return new ResultData(Result.SUCCESS, "删除成功", null); | ||||
| } | } | ||||
| @ApiOperation("根据id查询接口") | @ApiOperation("根据id查询接口") | ||||
| @GetMapping("/findById") | @GetMapping("/findById") | ||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | ||||
| public ResultData findById(Long id) { | public ResultData findById(Long id) { | ||||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponService.getById(id)); | return new ResultData(Result.SUCCESS,"查询成功",wxCouponService.getById(id)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import com.simple.annotation.AuthIgnore; | |||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.domain.po.WxAppinfo; | import com.simple.domain.po.WxAppinfo; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| @@ -10,6 +11,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.lang3.StringUtils; | |||||
| 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; | ||||
| @@ -40,15 +42,22 @@ public class WxPayOrderController extends BaseController { | |||||
| private WxPayOrderService wxPayOrderService; | private WxPayOrderService wxPayOrderService; | ||||
| @ApiOperation(value = "发起微信小程序支付订单") | @ApiOperation(value = "发起微信小程序支付订单") | ||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "orderId", value = "订单ID", required = true, dataType = "Long"), | |||||
| @ApiImplicitParam(name = "payVendor", value = "支付发起渠道:0-微信小程序", defaultValue = "0",required = false, dataType = "Integer") | |||||
| }) | |||||
| @RequestMapping(value = "/create", method = RequestMethod.POST) | @RequestMapping(value = "/create", method = RequestMethod.POST) | ||||
| public ResultData _create(WxPayOrder record, HttpServletRequest request) throws Exception { | |||||
| logger.info("payment wechat, order create, param : " + record.toString()); | |||||
| public ResultData _create(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws Exception { | |||||
| logger.info("/api/pay/create" + paramMap.toString()); | |||||
| String orderIdStr = paramMap.get("orderId"); | |||||
| if (StringUtils.isBlank(orderIdStr)) { | |||||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||||
| } | |||||
| WxCUser user = getUser(); | WxCUser user = getUser(); | ||||
| WxAppinfo appInfo = getAppInfo(user.getAppId()); | WxAppinfo appInfo = getAppInfo(user.getAppId()); | ||||
| Long orderId = Long.valueOf(orderIdStr); | |||||
| WxPayOrder record = new WxPayOrder(); | |||||
| record.setOrderId(orderId); | |||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | ||||
| @@ -66,7 +75,8 @@ public class WxPayOrderController extends BaseController { | |||||
| * @return 接收微信异步通知 | * @return 接收微信异步通知 | ||||
| * @throws Exception 可能产生的任何异常 | * @throws Exception 可能产生的任何异常 | ||||
| */ | */ | ||||
| @RequestMapping(value = "/notify", method = RequestMethod.POST) | |||||
| @AuthIgnore | |||||
| @RequestMapping(value = "/notify/pay", method = RequestMethod.POST) | |||||
| public String __doNotify(HttpServletRequest request) throws Exception { | public String __doNotify(HttpServletRequest request) throws Exception { | ||||
| Map<String, String> paramMap = null; | Map<String, String> paramMap = null; | ||||
| String response; | String response; | ||||
| @@ -55,8 +55,7 @@ public class WxUserGrantController extends BaseController { | |||||
| Map resultMap = new HashMap(); | Map resultMap = new HashMap(); | ||||
| String appId = map.get("appId"); | String appId = map.get("appId"); | ||||
| String code = map.get("code"); | |||||
| String scene = map.get("scene"); | |||||
| String code = map.get("code"); | |||||
| String sceneAddress = map.get("sceneAddress"); | String sceneAddress = map.get("sceneAddress"); | ||||
| //登录凭证不能为空 | //登录凭证不能为空 | ||||
| if (StringUtils.isBlank(appId)) { | if (StringUtils.isBlank(appId)) { | ||||
| @@ -68,7 +67,7 @@ public class WxUserGrantController extends BaseController { | |||||
| // 通过appinfo得到tenant_id | // 通过appinfo得到tenant_id | ||||
| WxAppinfo wxAppinfo = getAppInfo(appId); | WxAppinfo wxAppinfo = getAppInfo(appId); | ||||
| WxMaService wxMaService = getWeappService(appId); | |||||
| WxMaService wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||||
| String token = null; | String token = null; | ||||
| String session_key = null; | String session_key = null; | ||||
| @@ -99,8 +98,6 @@ public class WxUserGrantController extends BaseController { | |||||
| token = user1.getToken(); | token = user1.getToken(); | ||||
| user1.setRegisterIp(ipaddress); | user1.setRegisterIp(ipaddress); | ||||
| user1.setSessionKey(session_key); | user1.setSessionKey(session_key); | ||||
| if (user1.getScene() == null) | |||||
| user1.setScene(scene); | |||||
| if (user1.getSceneAddress() == null) | if (user1.getSceneAddress() == null) | ||||
| user1.setSceneAddress(sceneAddress); | user1.setSceneAddress(sceneAddress); | ||||
| wxCUserService.saveOrUpdate(user1); | wxCUserService.saveOrUpdate(user1); | ||||
| @@ -110,8 +107,6 @@ public class WxUserGrantController extends BaseController { | |||||
| user.createToken(new Date()); | user.createToken(new Date()); | ||||
| token = user.getToken(); | token = user.getToken(); | ||||
| user.setRegisterIp(ipaddress); | user.setRegisterIp(ipaddress); | ||||
| if (user.getScene() == null) | |||||
| user.setScene(scene); | |||||
| if (user.getSceneAddress() == null) | if (user.getSceneAddress() == null) | ||||
| user.setSceneAddress(sceneAddress); | user.setSceneAddress(sceneAddress); | ||||
| @@ -1,9 +1,9 @@ | |||||
| spring: | spring: | ||||
| # JDBC | # JDBC | ||||
| datasource: | datasource: | ||||
| url: jdbc:mysql://202.165.179.86:3306/mallink?characterEncoding=UTF-8&useSSL=false | |||||
| username: mallone | |||||
| password: m@1l0ne123@# | |||||
| url: jdbc:mysql://localhost:3306/mallink?characterEncoding=UTF-8&useSSL=false | |||||
| username: userone | |||||
| password: 123456 | |||||
| type: com.alibaba.druid.pool.DruidDataSource | type: com.alibaba.druid.pool.DruidDataSource | ||||
| driver-class-name: com.mysql.jdbc.Driver | driver-class-name: com.mysql.jdbc.Driver | ||||
| filters: stat | filters: stat | ||||
| @@ -43,7 +43,7 @@ public class WxPayOrder implements Serializable { | |||||
| /***/ | /***/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="",name="tenantId") | ||||
| private Long tenantId; | |||||
| private String tenantId; | |||||
| /*创建时间**/ | /*创建时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") | ||||
| private Date createTime; | private Date createTime; | ||||
| @@ -83,10 +83,10 @@ public class WxPayOrder implements Serializable { | |||||
| /*支付失败原因**/ | /*支付失败原因**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="支付失败原因",name="failReason") | @io.swagger.annotations.ApiModelProperty(value="支付失败原因",name="failReason") | ||||
| private String failReason; | private String failReason; | ||||
| public Long getTenantId() { | |||||
| public String getTenantId() { | |||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| public void setTenantId(Long _tenantId) { | |||||
| public void setTenantId(String _tenantId) { | |||||
| tenantId = _tenantId; | tenantId = _tenantId; | ||||
| } | } | ||||
| public Date getCreateTime() { | public Date getCreateTime() { | ||||
| @@ -11,9 +11,9 @@ public class WxPay { | |||||
| protected static Logger log = LoggerFactory.getLogger(WxPay.class); | protected static Logger log = LoggerFactory.getLogger(WxPay.class); | ||||
| // 统一下单接口 | // 统一下单接口 | ||||
| private static final String UNIFIEDORDER_URL = "https://api.mch.weixin.qq.com/sandboxnew/pay/unifiedorder"; | |||||
| private static final String UNIFIEDORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder"; | |||||
| // 订单查询 | // 订单查询 | ||||
| private static final String ORDERQUERY_URL = "https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery"; | |||||
| private static final String ORDERQUERY_URL = "https://api.mch.weixin.qq.com/pay/orderquery"; | |||||
| // 关闭订单 | // 关闭订单 | ||||
| private static final String CLOSEORDER_URL = "https://api.mch.weixin.qq.com/pay/closeorder"; | private static final String CLOSEORDER_URL = "https://api.mch.weixin.qq.com/pay/closeorder"; | ||||
| // 撤销订单 | // 撤销订单 | ||||
| @@ -1,9 +1,6 @@ | |||||
| package com.simple.pay; | package com.simple.pay; | ||||
| import com.simple.utils.HashUtil; | |||||
| import com.simple.utils.Utility; | |||||
| import com.simple.utils.XmlUtil; | |||||
| import org.apache.commons.codec.Charsets; | |||||
| import com.simple.utils.*; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
| @@ -429,4 +426,21 @@ public class WxPayment { | |||||
| } | } | ||||
| return str; | return str; | ||||
| } | } | ||||
| public static void main(String[] args) { | |||||
| Map map = MapUtil.getOrderMap(); | |||||
| map.put("mch_id", "1451696902"); | |||||
| map.put("nonce_str", RandomUtils.getStr(32)); | |||||
| String sign = WxPayment.createSign(map, "9f779d18a174f83879be48574afcb6f6"); | |||||
| map.put("sign", sign); | |||||
| String response = WxPay.sanboxSignGet(map); | |||||
| System.out.println(response); | |||||
| /* | |||||
| <xml> | |||||
| <return_code><![CDATA[SUCCESS]]></return_code> | |||||
| <return_msg><![CDATA[ok]]></return_msg> | |||||
| <sandbox_signkey><![CDATA[eb68c9a387f33b3a94ab375b2ca30816]]></sandbox_signkey> | |||||
| </xml> | |||||
| */ | |||||
| } | |||||
| } | } | ||||
| @@ -152,6 +152,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| try { | try { | ||||
| // 保存订单 | // 保存订单 | ||||
| record.setId(orderNumber); | record.setId(orderNumber); | ||||
| record.setTenantId(user.getTenantId()); | |||||
| record.setOrderNumber(orderNumber); | record.setOrderNumber(orderNumber); | ||||
| record.setCUserId(user.getId()); | record.setCUserId(user.getId()); | ||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | ||||
| @@ -24,6 +24,7 @@ import com.simple.pay.WxPayment; | |||||
| import com.simple.service.WxOrderService; | import com.simple.service.WxOrderService; | ||||
| import com.simple.service.WxPayOrderService; | import com.simple.service.WxPayOrderService; | ||||
| import com.simple.utils.BeanUtils; | import com.simple.utils.BeanUtils; | ||||
| import com.simple.utils.MapUtil; | |||||
| import com.simple.utils.Utility; | import com.simple.utils.Utility; | ||||
| import com.simple.utils.XmlUtil; | import com.simple.utils.XmlUtil; | ||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| @@ -91,6 +92,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| record.setId(id); | record.setId(id); | ||||
| record.setTenantId(user.getTenantId()); | |||||
| record.setCUserId(user.getId()); | |||||
| record.setCreateTime(currentDate); | record.setCreateTime(currentDate); | ||||
| record.setUpdateTime(currentDate); | record.setUpdateTime(currentDate); | ||||
| int currentTime = Utility.convertDate2TimeStamp(currentDate); | int currentTime = Utility.convertDate2TimeStamp(currentDate); | ||||
| @@ -111,7 +114,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| // 统一下单 | // 统一下单 | ||||
| String noncestr = Utility.generate32UUID(); | String noncestr = Utility.generate32UUID(); | ||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | WxPayOrderP wxPayOrderP = new WxPayOrderP(); | ||||
| wxPayOrderP.setAppid(appInfo.getAppId()); | |||||
| wxPayOrderP.setOpenid(user.getOpenId()); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | wxPayOrderP.setMch_id(payAccount.getMchId()); | ||||
| wxPayOrderP.setNonce_str(noncestr); | wxPayOrderP.setNonce_str(noncestr); | ||||
| wxPayOrderP.setBody(order.getDetail()); | wxPayOrderP.setBody(order.getDetail()); | ||||
| @@ -119,7 +123,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | wxPayOrderP.setTotal_fee(order.getPayment()); | ||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | ||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | ||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.APP.name()); // 终端类型 | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | ||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime)); | wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime)); | ||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime + 15 * 60)); // 15分钟结束 | wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime + 15 * 60)); // 15分钟结束 | ||||
| @@ -131,12 +135,13 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| if ("SUCCESS".equals(result_no)) { | if ("SUCCESS".equals(result_no)) { | ||||
| String prepay_id = returnMap.get("prepay_id"); | String prepay_id = returnMap.get("prepay_id"); | ||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | ||||
| Map<String, String> sighMap = new HashMap<>(); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", returnMap.get("appid")); | sighMap.put("appId", returnMap.get("appid")); | ||||
| sighMap.put("timeStamp", timestamp); | sighMap.put("timeStamp", timestamp); | ||||
| sighMap.put("nonceStr", noncestr); | sighMap.put("nonceStr", noncestr); | ||||
| sighMap.put("package", "prepay_id="+prepay_id); | sighMap.put("package", "prepay_id="+prepay_id); | ||||
| String signAgent = WxPayment.createSign(sighMap, appInfo.getSecret()); | |||||
| sighMap.put("signType", "MD5"); | |||||
| String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | returnMap.put("timeStamp", timestamp); | ||||
| returnMap.put("nonceStr", noncestr); | returnMap.put("nonceStr", noncestr); | ||||
| returnMap.put("package", "prepay_id="+prepay_id); | returnMap.put("package", "prepay_id="+prepay_id); | ||||