业务功能
接口组使用说明,本接口专门为2g网络接口设计,在网络环境恶劣的情况下,下游可调用本接口组进行交易。
所有请求参数不能含中文、通知地址必须以http开头
本接口转为2g网络使用,通讯方式使用socket。
签名可以传16位(前16位)、也支持32位,为提高传输效率,建议使用16位签名。
如果机构号错误或系统异常,签名的key为空字符串。
签名字符不需要传递字符串的长度所以接口调用必须传递accessid、sign参数。
公共返回参数return_code、签名
本系统接口,仿照银联8583报文格式,去除位图和厂商等信息、开发人员严格按照文档中参数的顺序进行签名和发送
发送格式参数字节长度使用BCD码 + 参数ASCII字节码
例如:outer_order_no = test000000001;
长度 bcd(lenth(test000000001)) 1字节
参数值 outer_order_no.getBytes()
然后拼接长度和参数值示例代码如下:
// 示例 public static void main(String[] args) throws IOException { Socket client = new Socket(); OutputStream ops = null; InputStream ins = null; int timeoutConect = 5000; // 设置连接超时时间50秒 int timeoutRevice = 6000; // 接收数据超时时间60秒 long begintime = 0, endtime = 0; byte[] bytes = new byte[73]; int countSex = 0; //trans_type String transType = "A"; byte[] byte1lenth = ISO8583Utile.string2Bcd(transType.length()+""); byte[] byte1value = transType.getBytes("ASCII"); System.arraycopy(byte1lenth, 0, bytes, countSex, byte1lenth.length); countSex+=byte1lenth.length; System.arraycopy(byte1value, 0, bytes,countSex, byte1value.length); countSex+=byte1value.length; //assignid String assignid = "cpostest"; byte[] byte2lenth = ISO8583Utile.string2Bcd(assignid.length()+""); byte[] byte2value = assignid.getBytes("ASCII"); System.arraycopy(byte2lenth, 0, bytes, countSex, byte2lenth.length); countSex+=byte2lenth.length; System.arraycopy(byte2value, 0, bytes, countSex, byte2value.length); countSex+=byte2value.length; //merch_no String custoner_no = "88888888"; byte[] byte3lenth = ISO8583Utile.string2Bcd(custoner_no.length()+""); byte[] byte3value = custoner_no.getBytes("ASCII"); System.arraycopy(byte3lenth, 0, bytes, countSex, byte3lenth.length); countSex+=byte3lenth.length; System.arraycopy(byte3value, 0, bytes, countSex, byte3value.length); countSex+=byte3value.length; //outer_order_no String order_no = "test000000007"; byte[] byte4lenth = ISO8583Utile.string2Bcd(order_no.length()+""); byte[] byte4value = order_no.getBytes("ASCII"); System.arraycopy(byte4lenth, 0,bytes ,countSex , byte4lenth.length); countSex+=byte4lenth.length; System.arraycopy(byte4value, 0, bytes, countSex, byte4value.length); countSex+=byte4value.length; //total_amount String total_amount = "1000"; byte[] byte5lenth = ISO8583Utile.string2Bcd(total_amount.length()+""); byte[] byte5value = total_amount.getBytes("ASCII"); System.arraycopy(byte5lenth, 0, bytes, countSex, byte5lenth.length); countSex+=byte5lenth.length; System.arraycopy(byte5value, 0, bytes, countSex, byte5value.length); countSex+=byte5value.length; //url String url = "http://www.baidu.com/"; byte[] byte6lenth = ISO8583Utile.string2Bcd(url.length()+""); byte[] byte6value = url.getBytes("ASCII"); System.arraycopy(byte6lenth, 0, bytes, countSex, byte6lenth.length); countSex+=byte6lenth.length; System.arraycopy(byte6value, 0, bytes, countSex, byte6value.length); countSex+=byte6value.length; //pn String pn = "1219050500000001"; byte[] byte7lenth = ISO8583Utile.string2Bcd(pn.length()+""); byte[] byte7value = pn.getBytes("ASCII"); System.arraycopy(byte7lenth, 0, bytes, countSex, byte7lenth.length); countSex+=byte7lenth.length; System.arraycopy(byte7value, 0, bytes, countSex, byte7value.length); countSex+=byte7value.length; StringBuffer signStr = new StringBuffer(); signStr.append(assignid).append(custoner_no).append(order_no).append(total_amount).append(pn).append(transType); System.out.println("sign str is>>>>"+signStr.toString()); //sign String sign = SignUtils.signParams("48e70b51cab84019a2dddf2f03f13a38", signStr.toString()); byte[] byte8lenth = ISO8583Utile.string2Bcd(sign.length()+""); byte[] byte8value = sign.getBytes(); System.arraycopy(byte8lenth, 0, bytes, countSex, byte8lenth.length); countSex+=byte8lenth.length; System.arraycopy(byte8value, 0, bytes, countSex, byte8value.length); countSex+=byte8value.length; System.out.println("sender byte[] length:"+countSex); System.out.println("16 hex >"+ISO8583Utile.bytesToHexString(bytes)); log.info("** Send date to " + "39.107.230.207" +":" + "10020" ); try { begintime = System.currentTimeMillis(); client.connect(new InetSocketAddress(InetAddress.getByName("39.107.230.207"), 10020), timeoutConect); client.setSoTimeout(timeoutRevice); ops = client.getOutputStream(); ops.write(bytes); ops.flush(); ins = client.getInputStream(); byte[] _resultByte = new byte[1024]; int len = ins.read(_resultByte); if(len==-1){// throw new SocketTimeoutException(); } byte[] resultByte = new byte[len]; System.arraycopy(_resultByte, 0, resultByte, 0, len); //解析 System.out.println("saas return 16 hex >"+ISO8583Utile.bytesToHexString(resultByte)); int offsetAli = 0; int bytelen = 0; String str = ""; byte[] itemValuelen = new byte[1];// 域长度BCD StringBuffer stringBuffer = new StringBuffer(); //error_code System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"ASCII"); offsetAli += (bytelen+1); stringBuffer.append(str); System.out.println("return code is"+str); if(str.equals("10000")){ //out_trade_no System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"UTF-8"); offsetAli += (bytelen+1); stringBuffer.append(str); System.out.println("return out_trade_no is"+str); //trade_no System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"UTF-8"); offsetAli += (bytelen+1); stringBuffer.append(str); System.out.println("return trade_no is"+str); //qr_code System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"UTF-8"); offsetAli += (bytelen+1); stringBuffer.append(str); System.out.println("return qr_code is"+str); //sign System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"ASCII"); String up_sign = SignUtils.signParams("48e70b51cab84019a2dddf2f03f13a38", stringBuffer.toString()); System.out.println("up return sign is "+str); System.out.println("local sign is "+up_sign); }else{ //errorMsg System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"UTF-8"); offsetAli += (bytelen+1); stringBuffer.append(str); System.out.println("return msg is"+str); //sign System.arraycopy(resultByte, offsetAli, itemValuelen, 0, 1); str = ISO8583Utile.bcd2String(itemValuelen, false); bytelen = Integer.parseInt(str);// 域真实长度 str = new String(resultByte, offsetAli + 1, bytelen,"ASCII"); String up_sign = SignUtils.signParams("48e70b51cab84019a2dddf2f03f13a38", stringBuffer.toString()); System.out.println("up return sign is "+str); System.out.println("local sign is "+up_sign); } System.out.println(resultByte.length); } catch (SocketTimeoutException e) { throw e; } catch (IOException e) { throw e; } finally { endtime = System.currentTimeMillis(); log.info("** use time: "+(endtime - begintime)+" ms"); if (ins != null) ins.close(); if (ops != null) ops.close(); if (client != null) { try { client.close(); } catch (IOException e) { log.info("close socket fail",e); e.printStackTrace(); } } } }
文档更新时间: 2025-02-27 16:40 作者:admin