-
Notifications
You must be signed in to change notification settings - Fork 1.1k
微信退款MCH
Yi Li edited this page Apr 9, 2018
·
1 revision
//设置一次即可
LocalHttpClient.initMchKeyStore("mch_id","apifile.p12");
SecapiPayRefund secapiPayRefund = new SecapiPayRefund();
secapiPayRefund.setAppid("");
secapiPayRefund.setNotify_url("");
secapiPayRefund.setMch_id("");
// TODO 设置secapiPayRefund
SecapiPayRefundResult result = PayMchAPI.secapiPayRefund(secapiPayRefund, "mch_key");
// TODO 修改业务状态
package weixin.popular.example;
import java.io.IOException;
import java.nio.charset.Charset;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import weixin.popular.bean.paymch.MchBaseResult;
import weixin.popular.bean.paymch.RefundNotifyReqInfo;
import weixin.popular.bean.paymch.SecapiPayRefundNotify;
import weixin.popular.support.ExpireKey;
import weixin.popular.support.expirekey.DefaultExpireKey;
import weixin.popular.util.PayUtil;
import weixin.popular.util.StreamUtils;
import weixin.popular.util.XMLConverUtil;
/**
* 退款回调通知
*
* @author LiYi
*
*/
public class SecapiPayRefundNotifyServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
private String key; // mch key
// 重复通知过滤
private static ExpireKey expireKey = new DefaultExpireKey();
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 获取请求数据
String xmlData = StreamUtils.copyToString(request.getInputStream(), Charset.forName("utf-8"));
// 转换数据对象
SecapiPayRefundNotify refundNotify = XMLConverUtil.convertToObject(SecapiPayRefundNotify.class, xmlData);
// 退款通知成功
if (refundNotify != null && "SUCCESS".equals(refundNotify.getReturn_code())) {
// 解密数据 req_info
RefundNotifyReqInfo refundNotifyReqInfo = PayUtil.decryptRefundNotifyReqInfo(refundNotify.getReq_info(),
key);
if (refundNotifyReqInfo == null) {
MchBaseResult baseResult = new MchBaseResult();
baseResult.setReturn_code("FAIL");
baseResult.setReturn_msg("ERROR");
response.getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
return;
}
// 业务处理标记检查
if (!expireKey.exists("WX_REFUND_NOTIFY" + refundNotifyReqInfo.getRefund_id())) {
// 添加业务处理标记
expireKey.add("WX_REFUND_NOTIFY" + refundNotifyReqInfo.getRefund_id(), 60);
// TODO 添加业务代码,修改退款申请状态
}
}
MchBaseResult baseResult = new MchBaseResult();
baseResult.setReturn_code("SUCCESS");
baseResult.setReturn_msg("OK");
response.getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
}
}
获取token
- TokenAPI access_token 获取
- MediaAPI 多媒体上传下载(临时素材)
- MaterialAPI 永久素材
- MenuAPI 菜单、个性化菜单
- MessageAPI 信息发送(客服消息、群发消息、模板消息)
- PayAPI 支付订单相关接口
- PayMchAPI 支付订单、红包、企业付款、代扣费(商户平台版)
- QrcodeAPI 二维码
- SnsAPI 网签授权
- UserAPI 用户管理、分组、标签、黑名单
- ShorturlAPI 长链接转短链接
- TicketAPI JSAPI ticket
- ComponentAPI 第三方平台开发
- CallbackipAPI 获取微信服务器IP地址
- ClearQuotaAPI 接口调用频次清零
- PoiAPI 微信门店 @Moyq5 (贡献)
- CardAPI 微信卡券 @Moyq5 (贡献)
- ShakearoundAPI 微信摇一摇周边 @Moyq5 (贡献)
- DatacubeAPI 数据统计 @Moyq5 (贡献)
- CustomserviceAPI 客服功能 @ConciseA (贡献)