Commit 405659b4 by YG8999

支付回调

parent 02cb26ea
......@@ -18,7 +18,7 @@ import javax.servlet.http.HttpServletRequest;
*/
@Slf4j
@RestController
@RequestMapping("api/admin/payment/callback")
@RequestMapping("/admin/payment/callback")
@Api(tags = "支付回调")
public class CallbackController {
......
......@@ -32,9 +32,9 @@ public class PayConstants {
// 微信查询订单
public static final String WX_PAY_ORDER_QUERY_API_URI = "pay/orderquery";
// 微信支付回调地址
public static final String WX_PAY_NOTIFY_API_URI = "/api/admin/payment/callback/wechat";
public static final String WX_PAY_NOTIFY_API_URI = "/prod-api/admin/payment/callback/wechat";
// 微信退款回调地址
public static final String WX_PAY_REFUND_NOTIFY_API_URI = "/api/admin/payment/callback/wechat/refund";
public static final String WX_PAY_REFUND_NOTIFY_API_URI = "/prod-api/admin/payment/callback/wechat/refund";
public static final String WX_PAY_SIGN_TYPE_MD5 = "MD5";
public static final String WX_PAY_SIGN_TYPE_SHA256 = "HMAC-SHA256";
......
......@@ -213,7 +213,7 @@ public class WeChatConstants {
//微信支付接口请求地址
public static final String PAY_API_URL = "https://api.mch.weixin.qq.com/";
public static final String PAY_API_URI = "pay/unifiedorder";
public static final String PAY_NOTIFY_API_URI_WECHAT = "/api/admin/payment/callback/wechat";
public static final String PAY_NOTIFY_API_URI_WECHAT = "/prod-api/admin/payment/callback/wechat";
// 公共号退款
public static final String PAY_REFUND_API_URI_WECHAT = "secapi/pay/refund";
......@@ -379,4 +379,16 @@ public class WeChatConstants {
public static final String WECAHT_CALLBACK_EVENT_SPU_AUDIT = "open_product_spu_audit";
/** 微信小程序回调,品牌审核回调事件 */
public static final String WECAHT_CALLBACK_EVENT_BRAND_AUDIT = "open_product_brand_audit";
// 微信回调标识
/**
* 通用成功标识
*/
public static final String SUCCESS = "SUCCESS";
/**
* 通用失败标识
*/
public static final String FAIL = "FAIL";
}
......@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register", "/captchaImage").permitAll()
.antMatchers("/login", "/register", "/captchaImage", "/admin/payment/callback/**").permitAll()
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
......
......@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.config.WeChatConfig;
import share.common.constant.Constants;
import share.common.constant.WeChatConstants;
import share.common.core.redis.RedisUtil;
import share.common.enums.OrderStatusEnum;
import share.common.enums.OrderTypeEnum;
......@@ -85,7 +86,7 @@ public class CallbackServiceImpl implements CallbackService {
HashMap<String, Object> map = WxPayUtil.processResponseXml(xmlInfo);
// 通信是否成功
String returnCode = (String) map.get("return_code");
if (!returnCode.equals(Constants.SUCCESS)) {
if (!returnCode.equals(WeChatConstants.SUCCESS)) {
sb.append("<return_code><![CDATA[SUCCESS]]></return_code>");
sb.append("<return_msg><![CDATA[OK]]></return_msg>");
sb.append("</xml>");
......@@ -94,7 +95,7 @@ public class CallbackServiceImpl implements CallbackService {
}
// 交易是否成功
String resultCode = (String) map.get("result_code");
if (!resultCode.equals(Constants.SUCCESS)) {
if (!resultCode.equals(WeChatConstants.SUCCESS)) {
sb.append("<return_code><![CDATA[SUCCESS]]></return_code>");
sb.append("<return_msg><![CDATA[OK]]></return_msg>");
sb.append("</xml>");
......@@ -178,7 +179,7 @@ public class CallbackServiceImpl implements CallbackService {
logger.error("wechat pay error : 业务异常==》" + e.getMessage());
}
sb.append("</xml>");
logger.error("wechat callback response : " + sb.toString());
logger.info("wechat callback response : " + sb.toString());
return sb.toString();
}
......@@ -277,7 +278,7 @@ public class CallbackServiceImpl implements CallbackService {
notifyRecord.setColums(_strMap2ObjMap(respMap));
// 这里的可以应该根据小程序还是公众号区分
String return_code = respMap.get("return_code");
if (return_code.equals(Constants.SUCCESS)) {
if (return_code.equals(WeChatConstants.SUCCESS)) {
String appid = respMap.get("appid");
String signKey = getSignKey(appid);
// 解码加密信息
......@@ -289,7 +290,7 @@ public class CallbackServiceImpl implements CallbackService {
notifyRecord.setColums(_strMap2ObjMap(infoMap));
String refund_status = infoMap.get("refund_status");
refundRecord.set("isRefund", refund_status.equals(Constants.SUCCESS));
refundRecord.set("isRefund", refund_status.equals(WeChatConstants.SUCCESS));
} catch (Exception e) {
refundRecord.set("isRefund", false);
logger.error("微信退款回调异常,e==》" + e.getMessage());
......
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -129,6 +130,7 @@ public class OrderPayServiceImpl implements OrderPayService {
vo.setSign_type(PayConstants.WX_PAY_SIGN_TYPE_MD5);
vo.setAttach(JSONObject.toJSONString(attachVo));
vo.setOut_trade_no(BaseUtil.getOrderNo("wxNo"));
vo.setBody(StrUtil.concat(true,sOrder.getTimeLong(),"小时麻将房畅玩!"));
// 订单中使用的是BigDecimal,这里要转为Integer类型
vo.setTotal_fee(sOrder.getPayPrice().multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue());
vo.setNotify_url(apiDomain + PayConstants.WX_PAY_NOTIFY_API_URI);
......
......@@ -9,6 +9,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import share.common.constant.Constants;
import share.common.constant.PayConstants;
import share.common.constant.WeChatConstants;
import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
import share.common.utils.XmlUtil;
......@@ -50,6 +51,10 @@ public class WxPayUtil {
return respData;
} else if (return_code.equals(Constants.SUCCESS)) {
return respData;
} else if (return_code.equals(WeChatConstants.FAIL)) {
return respData;
} else if (return_code.equals(WeChatConstants.SUCCESS)) {
return respData;
} else {
throw new BaseException(String.format("return_code value %s is invalid in XML: %s", return_code, xmlStr));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment