前段时间项目要接工银聚富通,上网找个好多有关资料感觉都不太合适,后来自己一点点摸索,最后完成了需求.项目是微信小程序商城.用户下单到门店,发起支付,并将工行支付返回的参数返回给前端,前端根据参数调起微信小程序支付,其大致流程是,用户下单->门店->微信支付发起->返回支付参数->微信唤醒支付页面->用户输入密码支付.
前提:在用户下单的门店必须有工行的商户号,否则无法支付,所以在代理商App那里加了一个工行注册接口,就是说代理商在代理商App注册成功后,还需要向工行注册为子商户.代理商下包含多个门店,只需要代理商注册商户号,其下门店都是可以支付成功的.首先得使你支付的门店或代理商成为工银聚富通的子商户,接下来我们可以看下子商户是怎样注册的.
聚富通商户注册页
子商户注册页详细信息都在以上超链接中,在这里有一个坑人的地方,请求地址,文档介绍中的请求地址是V2,实际需要V3
唯一注意点:请求路径:**https://gw.open.icbc.com.cn/ui/jft/ui/vendor/register/V3**
还有一点就是:这个请求是一个servlet,因为现在大部分项目都是springBoot微服务项目的,在加入servlet需要在启动类加入以下注解,在项目启动能保证你的servlet能被扫描到

以下是工行聚富通给的测试代码
String APP_ID = "Oikeclo001";
String MY_PRIVATE_KEY = "[需替换]应用方私钥,由应用方生成公私钥对,并将公钥上传至工行API开放平台";
String host = "[需替换]工行API网关地址";
String apiUrl= host+"/ui/jft/ui/vendor/register/V2";
String SIGN_TYPE = "RSA2";
//签名类型为RSA2时,需传入appid,私钥和网关公钥,签名类型使用定值IcbcConstants.SIGN_TYPE_RSA2,其他参数使用缺省值
UiIcbcClient client = new UiIcbcClient(APP_ID, SIGN_TYPE, MY_PRIVATE_KEY, IcbcConstants.CHARSET_UTF8);
JftUiVendorRegisterRequestV2 request = new JftUiVendorRegisterRequestV2();
request.setServiceUrl(apiUrl);
JftUiVendorRegisterRequestV2Biz bizContent = new JftUiVendorRegisterRequestV2Biz();
//必输
bizContent.setAppId("10000000000000004473");
//必输
bizContent.setOutVendorId("66666666622001234001");
//bizType 为07时 不输;普通子商户必输
bizContent.setOutUserId("66666666660055005501");
//bizType 为07时 不输;普通子商户必输
bizContent.setOutUpperVendorId("66666666633456768843");
// 票据子商户必输 且必须为07;分润客户必输,且必须为26
bizContent.setBizType("07");
request.setBizContent(bizContent);
resp.setHeader("Content-Type", "text/html;charset=" + IcbcConstants.CHARSET_UTF8);
PrintWriter out = resp.getWriter();
// System.out.println(client.buildPostForm(request));
out.write("<html>");
out.write("<head>");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
+ IcbcConstants.CHARSET_UTF8 + "\">");
out.write("</head>");
out.write("<body>");
out.write(client.buildPostForm(request));
out.write("</body>");
out.write("</html>");
其实说白了就是我们填写一些必要参数向工行发送请求,请求成功会唤起工行聚富通的注册页面,如果你的参数都是对的话,启动项目请求你的servlet就会出现工行聚富通的子商户注册页,如下图:

以下是我的demo,可以根据实际情况在项目需要接入的时候来进行接入
访问地址: http://localhost:10001/test?outUserId=1000000097&outVendorId=1100000001
@WebServlet(urlPatterns = "/test")
public class RegisterServlet extends HttpServlet {
protected static final String APIGW_PUBLIC_KEY = "网关公钥";
String APP_ID = "appId";
String MY_PRIVATE_KEY ="私钥";
private static final String host = "https://gw.open.icbc.com.cn";
private static final String apiUrl = host+"/ui/jft/ui/vendor/register/V3";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String outUserId = req.getParameter("outUserId");
String outVendorId = req.getParameter("outVendorId");
UiIcbcClient client = new UiIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY,
IcbcConstants.CHARSET_UTF8);
JftUiVendorRegisterRequestV2 request = new JftUiVendorRegisterRequestV2();
request.setServiceUrl("https://gw.open.icbc.com.cn/ui/jft/ui/vendor/register/V3");
JftUiVendorRegisterRequestV2Biz bizContent = new JftUiVendorRegisterRequestV2Biz();
bizContent.setAppId(APP_ID);
bizContent.setOutUserId(outUserId);
bizContent.setOutVendorId(outVendorId);
bizContent.setOutUpperVendorId(APP_ID);
// bizContent.setBizType("07");
request.setBizContent(bizContent);
resp.setHeader("Content-Type", "text/html;charset="
+ IcbcConstants.CHARSET_UTF8);
PrintWriter out = resp.getWriter();
out.write("<html>");
out.write("<head>");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
+ IcbcConstants.CHARSET_UTF8 + "\">");
out.write("</head>");
out.write("<body>");
try {
out.write(client.buildPostForm(request));
} catch (IcbcApiException e) {
e.printStackTrace();
}
out.write("</body>");
out.write("</html>");
System.out.println(resp.getStatus());
}
}
参数一定要对,不然当你发起请求的时候会出现好多诸如以下的错误,切记多看文档给的参数

版权声明:本文为qq_41934990原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。