公司最近要将原先的1.0.0.0支付接口升级为1.0.0.11 版本,在工行技术人员给出的实例中有ASP、C、JAVA的就是没有ASP.NET与PHP的(先鄙视下)。
下面是根据1.0.0.0转换成1.0.0.11的并参考了http://www.liufangfang.net/blog/148 这个网站
首先将工行提供的 ICBCEBankUtil.dll 注册(如何注册就不说了)注册好后在项目中引用(infosecapi.dll刚开始一直在这个文件上纠缠,结果......)。
然后将public.crt、商户.crt、商户.key 这三个文件放到工程下,
下面就是具体代码了
ICBCTest
1 /// <summary> 2 /// 工商银行调用接口示例 3 /// </summary> 4 public class ICBCTest 5 { 6 string strCertFN = @"E:\XXXX\public.crt"; 7 string strCertFNM = @"E:\XXX\商户.crt"; 8 string strKeyFN = @"E:\XXX\商户.key"; 9 string strKey = "88888888"; 10 11 /// <summary> 12 /// 获取工商银行验证信息 13 /// </summary> 14 /// <returns></returns> 15 public ICBC GetCheckInfo(ICBC argIcbc) 16 { 17 string strMerSignMsg = string.Empty; 18 B2CUtil icbcObj = new B2CUtil(); 19 20 if (icbcObj.init(strCertFN, strCertFNM, strKeyFN, strKey) == 0) 21 { 22 argIcbc.MerSignMsg = icbcObj.signC(argIcbc.TranData, argIcbc.TranData.Length); 23 argIcbc.MerCert = icbcObj.getCert(1); 24 argIcbc.TranData = Encode(argIcbc.TranData); 25 } 26 else 27 { 28 return null; 29 } 30 return argIcbc; 31 } 32 33 /// <summary> 34 /// 获取工商银行验证信息 35 /// </summary> 36 /// <returns></returns> 37 public ICBC GetCheckReturnInfo(ICBC argIcbc) 38 { 39 string strMerSignMsg = string.Empty; 40 B2CUtil icbcObj = new B2CUtil(); 41 42 if (icbcObj.init(strCertFN, strCertFNM, strKeyFN, strKey) == 0) 43 { 44 argIcbc.TranData = Decode(argIcbc.TranData); 45 46 if (icbcObj.verifySignC(argIcbc.TranData, argIcbc.TranData.Length, argIcbc.MerSignMsg, argIcbc.MerSignMsg.Length) == 0) //判断验证银行签名是否成功 47 { 48 argIcbc.IsCheck = true; 49 } 50 else 51 argIcbc.IsCheck = true; 52 } 53 else 54 { 55 argIcbc.IsCheck = false; 56 } 57 return argIcbc; 58 } 59 60 61 62 /// <summary> 63 /// 加密 64 /// </summary> 65 /// <param name="data">加密字符串</param> 66 /// <returns>string</returns> 67 public string Encode(string data) 68 { 69 try 70 { 71
72 //这里是加密算法
73
74 } 75 catch (Exception e) 76 { 77 throw; 78 } 79 } 80 81 /// <summary> 82 /// 解密 83 /// </summary> 84 /// <param name="str">解密字符串</param> 85 /// <returns>string</returns> 86 public string Decode(string str) 87 { 88
89
90 //这里是解密算法
91 } 92 93 94 }
工行信息实体类(这些属性是什么意思一般在开发文档中都有详细的提到)
View ICBC
1 public class ICBC 2 { 3 private string _orderPostUrl = "https://mybank.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet 4 "; 5 private string _interfaceName = "ICBC_PERBANK_B2C"; 6 private string _interfaceVersion = "1.0.0.11"; 7 private string _orderid; 8 private string _amount; 9 private string _curType = "001"; 10 private string _merID = "XXXXXX"; 11 private string _merAcct = "XXXXXXXXXXXX"; 12 private string _verifyJoinFlag = "0"; 13 private string _notifyType = "HS"; 14 private string _merURL; 15 private string _resultType = "1"; 16 private string _orderDate = System.DateTime.Now.ToString("yyyyMMddHHmmss"); 17 private string _merSignMsg; 18 private string _merCert; 19 private string _goodsID = "001"; 20 private string _goodsName = "XXXX"; 21 private string _goodsNum; 22 private string _carriageAmt; 23 private string _remark1; 24 private string _remark2; 25 private string _merHint; 26 private string _tranData; 27 private string _merReference = "localhost"; 28 29 private bool _isCheck = false; 30 31 /// <summary> 32 /// 是否检测成功 33 /// </summary> 34 public bool IsCheck 35 { 36 get { return _isCheck; } 37 set { _isCheck = value; } 38 } 39 40 public string MerReference 41 { 42 get { return _merReference; } 43 set { _merReference = value; } 44 } 45 46 /// <summary> 47 /// 报文数据 48 /// </summary> 49 public string TranData 50 { 51 get { return _tranData; } 52 set { _tranData = value; } 53 } 54 55 /// <summary> 56 /// 工商支付接口路径 57 /// </summary> 58 public string OrderPostUrl 59 { 60 get { return _orderPostUrl; } 61 set { _orderPostUrl = value; } 62 } 63 64 /// <summary> 65 /// 接口名称 66 /// </summary> 67 public string InterfaceName 68 { 69 get { return _interfaceName; } 70 set { _interfaceName = value; } 71 } 72 73 /// <summary> 74 /// 接口版本号 75 /// </summary> 76 public string InterfaceVersion 77 { 78 get { return _interfaceVersion; } 79 set { _interfaceVersion = value; } 80 } 81 82 /// <summary> 83 /// 订单号 84 /// </summary> 85 public string Orderid 86 { 87 get { return _orderid; } 88 set { _orderid = value; } 89 } 90 91 /// <summary> 92 /// 订单金额 93 /// </summary> 94 public string Amount 95 { 96 get { return _amount; } 97 set { _amount = value; } 98 } 99 100 /// <summary> 101 /// 支付币种 RMB:001 102 /// </summary> 103 public string CurType 104 { 105 get { return _curType; } 106 set { _curType = value; } 107 } 108 109 /// <summary> 110 /// 商户代码 111 /// </summary> 112 public string MerID 113 { 114 get { return _merID; } 115 set { _merID = value; } 116 } 117 118 /// <summary> 119 /// 商户账号 120 /// </summary> 121 public string MerAcct 122 { 123 get { return _merAcct; } 124 set { _merAcct = value; } 125 } 126 127 /// <summary> 128 /// 检验联名标志 129 /// 取值“1”:客户支付时,网银判断该客户是否与商户联名,是则按上送金额扣帐,否则展现未联名错误; 130 /// 取值“0”:不检验客户是否与商户联名,按上送金额扣帐。 131 /// </summary> 132 public string VerifyJoinFlag 133 { 134 get { return _verifyJoinFlag; } 135 set { _verifyJoinFlag = value; } 136 } 137 138 /// <summary> 139 /// 通知类型 140 /// 取值“HS”:在交易完成后实时将通知信息以HTTP协议POST方式,主动发送给商户,发送地址为商户端随订单数据提交的接收工行支付结果的URL即表单中的merURL字段; 141 /// 取值“AG”:在交易完成后不通知商户。商户需使用浏览器登录工行的B2C商户服务网站,或者使用工行提供的客户端程序API主动获取通知信息。 142 /// </summary> 143 public string NotifyType
|
请发表评论