关于个人如何接入微信支付接口,适用于h5,小程序等应用场景,

众所周知,要想使用微信支付实现公众号、商城、小程序、h5网页等产品或者服务购买,需要申请微信小程序或者服务号,并且要企业认证,还要提交微信支付申请,其流程繁琐的很,

需要材料与具体流程如下;

1.营业执照,(现办理的还要等公示,一般1-3天,猥琐一点的地区一周,再猥琐一点的10天半个月都有可能)
2.身份证正反面照片,
3.法人银行账户,
4.还是视频乱七八糟的一堆,
5.审核时间,大概一周,
6.300元微信认证费用,
7如果涉及到公众号迁移什么的又是一周,

1.PayJs三方支付接口,

可支持个人微信支付的接入(找了一宿),申请简单,身份证号,手机号,再留个银行卡号就行了,最重要的是申请审核速度巨tm的快,两小时左右即可完成审核,传送门 https://payjs.cn/
注册这个需要花费300元的接口使用费,以及每次支付的1.38%-2.38%服务费;
其功能跟微信支付是一样的,

微信h5支付 demo 微信h5支付接口如何开通?_json


注册之后你会拿到一个商户号和一个对应的密匙,api也写的比较详细

微信h5支付 demo 微信h5支付接口如何开通?_json_02

java_Demo,拽到本地直接调用即可。
public class PayJs {

    private final MediaType MediaTypeJson = MediaType.parse("application/json; charset=utf-8");

    /**
     * 域名
     */
    private final String host = "https://payjs.cn";

    /**
     * 商户号
     */
    private String mchid;

    /**
     * 秘钥
     */
    private String key;

    /**
     * 连接超时时间
     */
    private long connectTimeout = 3000L;

    /**
     * 读取超时时间
     */
    private long readTimeout = 5000L;

    public PayJs(String mchid, String key) {
        this.mchid = mchid;
        this.key = key;
    }

    public PayJs(String mchid, String key, long connectTimeout, long readTimeout) {
        this.mchid = mchid;
        this.key = key;
        this.connectTimeout = connectTimeout;
        this.readTimeout = readTimeout;
    }

    /**
     * 获取回调数据
     * 官方文档<a>https://help.payjs.cn/api-lie-biao/jiao-yi-xin-xi-tui-song.html</a>
     * @param response 回调数据
     * @return 回调数据
     * @throws PayJsException 异常
     */
    public NotifyResponse notify(NotifyResponse response) throws PayJsException {
        String sign = response.getSign();
        response.setSign(null);
        String sign1 = SignUtil.getSign(response, this.key);
        if (!sign.equals(sign1)) {
            throw new PayJsException("签名不匹配");
        }
        return response;
    }

    /**
     * 退款
     * 官方文档<a>https://help.payjs.cn/api-lie-biao/tui-kuan.html</a>
     * @param request 请求数据
     * @return 返回数据
     * @throws PayJsException 异常
     */
    public RefundResponse refund(RefundRequest request) throws PayJsException {
        final String url = this.host + "/api/refund";
        request.setSign(SignUtil.getSign(request, this.key));

        return this.doRequest(url, request, RefundResponse.class);
    }

    /**
     * 获取jsapi所需参数
     * 官方文档<a>https://help.payjs.cn/api-lie-biao/jsapiyuan-sheng-zhi-fu.html</a>
     * @param request 请求数据
     * @return 返回数据
     * @throws PayJsException 异常
     */
    public JsapiResponse jsapi(JsapiRequest request) throws PayJsException {
        final String url = this.host + "/api/jsapi";
        request.setSign(SignUtil.getSign(request, this.key));

        return this.doRequest(url, request, JsapiResponse.class);
    }

    /**
     * 收银台支付
     * 官方文档<a>https://help.payjs.cn/api-lie-biao/shou-yin-tai-zhi-fu.html</a>
     * @param request 请求数据
     * @return 返回URL地址,需要前端跳转
     */
    public String cashier(CashierRequest request) {

        final String url = this.host + "/api/cashier";

        request.setMchid(this.mchid);
        request.setSign(SignUtil.getSign(request, this.key));

        SerializeConfig config = new SerializeConfig();
        config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        String jsonString = JSONObject.toJSONString(request, config);
        JSONObject jsonObject = JSONObject.parseObject(jsonString);

        // 拼接url
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(url);
        stringBuilder.append("?");
        jsonObject.entrySet().forEach(entry -> stringBuilder.append(entry.getKey() + "=" + entry.getValue() + "&"));

        return stringBuilder.toString();
    }

    /**
     * 关闭订单
     * 官方文档<a>https://help.payjs.cn/api-lie-biao/guan-bi-ding-dan.html</a>
     * @param request 请求数据
     * @return 返回数据
     * @throws PayJsException 异常
     */
    public CloseResponse close(CloseRequest request) throws PayJsException {
        final String url = this.host + "/api/close";
        request.setSign(SignUtil.getSign(request, this.key));

        return this.doRequest(url, request, CloseResponse.class);
    }

    /**
     * 订单查询
     * 官方文档<a>https://help.payjs.cn/api-lie-biao/ding-dan-cha-xun.html</a>
     * @param request 请求数据
     * @return 返回数据
     * @throws PayJsException 异常
     */
    public CheckResponse check(CheckRequest request) throws PayJsException {
        final String url = this.host + "/api/check";
        request.setSign(SignUtil.getSign(request, this.key));

        return this.doRequest(url, request, CheckResponse.class);
    }

    /**
     * 发送请求
     * @param url 请求地址
     * @param requestObj 请求数据对象
     * @param tClass 返回对象类
     * @param <T> payjs返回数据
     * @return payjs返回数据
     * @throws PayJsException 异常
     */
    private <T extends PayJsResponse> T doRequest(String url, Object requestObj, Class<T> tClass) throws PayJsException {

        SerializeConfig config = new SerializeConfig();
        config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        String jsonString = JSONObject.toJSONString(requestObj, config);

        OkHttpClient client = new OkHttpClient().newBuilder()
                .connectTimeout(this.connectTimeout, TimeUnit.MILLISECONDS)
                .readTimeout(this.readTimeout, TimeUnit.MILLISECONDS)
                .build();

        RequestBody body = RequestBody.create(MediaTypeJson, jsonString);
        Request request = new Request.Builder()
                .url(url)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response;
        try {
            response = client.newCall(request).execute();
        } catch (IOException e) {
            log.error("发送请求出错:{}", e);
            throw new PayJsException("发送请求错误:" + e.getMessage());
        }

        String responseBody;
        try {
            responseBody = response.body().string();
        } catch (IOException e) {
            log.error("解析返回数据出错:{}", e);
            throw new PayJsException("解析返回数据出错:" + e.getMessage());
        }

        return JSON.parseObject(responseBody, tClass);
    }
}