• 大小: 4.22MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-17
  • 语言: 其他
  • 标签: 微信支付  

资源简介

spring+mybatis接入微信支付,支付宝支付(包含微信公众号支付和H5支付),可以作为独立的模块使用也可以作为公共的支付接口

资源截图

代码片段和文件信息

package com.lebo.pay.client;


import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lebo.pay.config.WechatConfig;
import com.lebo.pay.entity.WechatRefund;
import com.lebo.pay.entity.WechatRefundQuery;
import com.lebo.pay.entity.WechatUnifiedOrder;
import com.lebo.util.SignUtil;
import com.lebo.util.WebUtils;
import com.lebo.util.xmlUtil;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.TreeMap;

/**
 * 微信交易客户端
 * @author chenrui
 * @date 2018/06/11
 */
public class WechatClient {
    private String app_id;
    private String mch_id;
    private String app_secret;
    private String trade_type;

    private static Logger logger = LoggerFactory.getLogger(WechatClient.class);

    public WechatClient(String app_id String mch_id String app_secret String trade_type) {
        this.app_id = app_id;
        this.mch_id = mch_id;
        this.app_secret = app_secret;
        this.trade_type = trade_type;
    }

    /**
     * 统一下单会自动签名和补上noce_str
     * @return 下单后返回信息
     */
    public WechatUnifiedOrder.Response unifiedOrder(WechatUnifiedOrder unifiedOrder){
        unifiedOrder.setAppid(this.app_id);
        unifiedOrder.setMch_id(this.mch_id);
        if(StringUtils.isBlank(unifiedOrder.getTrade_type())){
         unifiedOrder.setTrade_type(this.trade_type);
        }
        //unifiedOrder.setSign_type(“MD5“);
        unifiedOrder.setNotify_url(WechatConfig.NOTIFY_PAY);
        unifiedOrder.setLimit_pay(“no_credit“);
        unifiedOrder.setNonce_str(nonce_str(16));
        unifiedOrder.setSign(sign(SignUtil.bean2TreeMap(unifiedOrder)).toUpperCase());
        String tempxmlStr = xmlUtil.beanToxml(new ByteArrayOutputStream() unifiedOrder);
        String requestxml = tempxmlStr!= null?tempxmlStr.substring(55):““;
        logger.debug(“xml转义后内容:“+requestxml);
        try {
            InputStreamEntity inputStreamEntity = new InputStreamEntity(
                    new ByteArrayInputStream(requestxml.getBytes(“UTF-8“)) ContentType.APPLICATION_xml);
            String resultxml = WebUtils.post(WechatConfig.UNIFIEDORDER_URLinputStreamEntity);
            logger.debug(“微信返回内容:“+resultxml);
            return resultxml!= null
                    ?xmlUtil.xmlToBean(resultxml WechatUnifiedOrder.Response.class)
                    :new WechatUnifiedOrder.Response(“FAIL“);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return new WechatUnifiedOrder.Response(“FAIL“);
    }


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-14 16:47  payDemo\
     文件        1075  2018-08-10 17:01  payDemo\.classpath
     文件          44  2018-08-07 21:05  payDemo\.gitignore
     文件        1083  2018-08-14 16:49  payDemo\.project
     目录           0  2018-08-14 16:47  payDemo\.settings\
     文件         567  2018-08-07 21:06  payDemo\.settings\.jsdtscope
     文件         430  2018-08-07 21:09  payDemo\.settings\org.eclipse.jdt.core.prefs
     文件          90  2018-08-07 21:09  payDemo\.settings\org.eclipse.m2e.core.prefs
     文件         732  2018-08-07 21:09  payDemo\.settings\org.eclipse.wst.common.component
     文件         321  2018-08-07 21:09  payDemo\.settings\org.eclipse.wst.common.project.facet.core.prefs.xml
     文件         346  2018-08-07 21:09  payDemo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2018-08-07 21:06  payDemo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2018-08-07 21:06  payDemo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     文件          50  2018-08-07 21:09  payDemo\.settings\org.eclipse.wst.validation.prefs
     目录           0  2018-08-14 16:47  payDemo\bin\
     目录           0  2018-08-14 16:47  payDemo\bin\com\
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\pay\
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\pay\client\
     文件        3839  2018-08-07 21:05  payDemo\bin\com\lebo\pay\client\WechatClient.class
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\pay\config\
     文件        1645  2018-08-07 21:05  payDemo\bin\com\lebo\pay\config\AliPayConfig.class
     文件        1921  2018-08-07 21:05  payDemo\bin\com\lebo\pay\config\WechatConfig.class
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\pay\controller\
     文件        4585  2018-08-07 21:05  payDemo\bin\com\lebo\pay\controller\baseController.class
     文件        6348  2018-08-07 21:05  payDemo\bin\com\lebo\pay\controller\PayController.class
     文件        2412  2018-08-07 21:05  payDemo\bin\com\lebo\pay\controller\WxApiController.class
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\pay\dao\
     文件         472  2018-08-07 21:05  payDemo\bin\com\lebo\pay\dao\DAO.class
     文件        2871  2018-08-07 21:05  payDemo\bin\com\lebo\pay\dao\DaoSupport.class
     目录           0  2018-08-14 16:47  payDemo\bin\com\lebo\pay\entity\
............此处省略150个文件信息

评论

共有 条评论