Biz-SIP業務中臺案例實戰(11)——ISO8583格式轉換器(iso-8583)

Biz-SIP金融級業務中臺(http://bizsip。bizmda。com)是一套基於領域驅動設計(DDD)架構,能快速構建金融級雲原生架構的服務整合中介軟體,整合了在金融場景裡錘鍊出來的最佳實踐。

Biz-SIP業務中臺支援多種報文型別的格式轉換器,包括XML、JSON、定長、有分隔符、ISO-8583等報文型別的解包和打包,格式轉換器可以在Source模組和Sink服務中進行配置和使用,實現打包(平臺標準報文格式轉換成外部報文格式)和解包(外部報文格式轉換成平臺標準報文格式)。

iso-8583型別的格式轉換器,能把Biz-SIP內部標準訊息報文,根據配置打包成外部的ISO8583格式報文;同時也直接把外部的ISO8583格式報文,解包成Biz-SIP內部標準訊息報文。

本節案例中是在Sink服務模組中,配置iso-8583格式轉換器,以實現ISO8583格式報文(velocity-split)的打包和解包:

Biz-SIP業務中臺案例實戰(11)——ISO8583格式轉換器(iso-8583)

其中,App層是透過Sink透傳App服務,直接讓呼叫方透過OpenAPI介面呼叫Sink服務(iso-8583-sink),Sink服務會把平臺內部標準格式(JSONObject物件,內部即JSON報文)進行打包成ISO8583格式報文,傳給通訊聯結器Connector,原包返回後再解包成平臺內部標準格式,響應給呼叫方。

具體程式碼和配置可以檢視Biz-SIP原始碼中的Sample相關測試案例(https://gitee。com/szhengye/biz-sip)

一、Sink層Sink服務的開發和配置

同樣,在Biz-SIP配置目錄的sink。yml中,配置對應的Sink服務:

- id: iso-8583-sink type: rest url: http://bizsip-sample-sink/iso-8583-sink converter: type: iso-8583 destination-id: ‘00010344’ source-id: ‘42430440’ fields: - index: 2 length: 19 unfixed: 2 name: accNo2 - index: 3 length: 6 name: processingCode3 - index: 4 length: 12 name: amt_trans4 - index: 5 length: 12 name: amt_settlmt5 - index: 6 length: 12 name: transactionAmount6 - index: 7 length: 10 name: transmsn_date_time7 - index: 9 length: 8 name: transmsn_date_time9 - index: 10 length: 8 name: transmsn_date_time10 - index: 11 length: 6 name: systemTraceAuditNumber11 - index: 12 length: 6 name: time_local_trans12 - index: 13 length: 4 name: date_local_trans13 - index: 14 length: 4 name: date_expr14 - index: 15 length: 4 name: date_settlmt15 - index: 16 length: 4 name: date_conv16 - index: 18 length: 4 name: mchnt_type18 - index: 19 length: 3 name: mchnt_cntry_code19 - index: 22 length: 3 name: pos_entry_mode_code22 - index: 23 length: 3 name: card_seq_num23 - index: 25 length: 2 name: pos_cond_code25 - index: 26 length: 2 name: pos_pin_cap_code26 - index: 28 length: 9 name: amt_fee28 - index: 32 length: 11 unfixed: 2 name: acq_inst_id_code32 - index: 33 length: 11 unfixed: 2 name: fwd_inst_id_code33 - index: 35 length: 37 unfixed: 2 name: track2_data35 - index: 36 length: 104 unfixed: 3 name: track3_data36 - index: 37 length: 12 name: retrivl_ref_num37 - index: 38 length: 6 name: authr_id_resp38 - index: 39 length: 2 name: resp_code39 - index: 41 length: 8 name: card_accptr_termnl_id41 - index: 42 length: 15 name: card_accptr_id42 - index: 43 length: 40 name: card_accptr_name_loc43 - index: 44 length: 25 unfixed: 2 name: addtnl_resp_code44 - index: 45 length: 76 unfixed: 2 name: track1_data45 - index: 48 length: 512 unfixed: 3 name: addtnl_data_private48 - index: 49 length: 3 name: currcy_code_trans49 - index: 50 length: 3 name: currcy_code_settlmt50 - index: 51 length: 3 name: currcy_code_cdhldr_bil51 - index: 52 length: 8 name: pin_data52 - index: 53 length: 16 name: security_control_info53 - index: 54 length: 40 unfixed: 3 name: addtnl_amt54 - index: 55 length: 255 unfixed: 3 name: ICC_data55 - index: 56 length: 255 unfixed: 3 name: token_par56 - index: 57 length: 100 unfixed: 3 name: issr_addtnl_data57 - index: 59 length: 600 unfixed: 3 name: detai_inquiring59 - index: 60 length: 100 unfixed: 3 name: reserved60 - index: 61 length: 200 unfixed: 3 name: ch_auth_info61 - index: 62 length: 200 unfixed: 3 name: switching_data62 - index: 63 length: 512 unfixed: 3 name: fin_net_data63 - index: 70 length: 3 name: net_mgr_info_code70 - index: 90 length: 42 name: ori_data_element90 - index: 96 length: 8 name: msg_security_code96 - index: 100 length: 11 unfixed: 2 name: rcvg_inst_id_code100 - index: 102 length: 28 unfixed: 2 name: acct_id_1_102 - index: 103 length: 28 unfixed: 2 name: acct_id_2_103 - index: 104 length: 512 unfixed: 3 name: trans_industry_app_inf104 - index: 113 length: 512 unfixed: 3 name: add_data113 - index: 117 length: 256 unfixed: 3 name: addtnl_data117 - index: 121 length: 100 unfixed: 3 name: national_sw_resved121 - index: 122 length: 100 unfixed: 3 name: acq_inst_resvd122 - index: 123 length: 100 unfixed: 3 name: issr_inst_resvd123 - index: 125 length: 256 unfixed: 3 name: addtnl_data125 - index: 128 length: 8 name: msg_authn_code128 connector: type: service class-name: com。bizmda。bizsip。sample。sink。service。EchoConnectorService

可以看到iso-8583-sink這個Sink服務,connector關聯了能把請求報文直接原包響應返回的EchoConnectorService類。而格式轉換器converter,則直接設定“type: iso-8583”,表示採用ISO8583格式轉換器,作為當前Sink服務的格式轉換器。

Sink服務的converter項下配置了destination-id和source-id引數,分別代表目的地址和源地址,fields下定義了ISO8583報文中各域的約定,index為域號,name為資料關聯的域名,length為域長度,unfixed為變長位數。

這個Sink服務沒有設定processor屬性,即為預設default型別,採用預設的預設Sink服務流程來處理的,處理步驟依次為:

呼叫格式轉換器converter對傳入報文進行打包;

對上步打包後的報文作為呼叫請求報文,呼叫通訊介面卡connector進行處理,並收到並返回響應報文;

呼叫格式轉換器converter對響應報文進行解包,並返回解包後的報文。

最後,還需要在SampleSinkApplication的應用配置檔案application-local。yml中,在bizsip。sink-id配置項中,增加iso-8583-sink以便啟動Sink服務:

bizsip: config-path: /var/bizsip/config sink-id: hello-sink,echo-sink,simple-xml-sink,velocity-json-sink,velocity-xml-sink,fixed-length-sink,velocity-split-sink,iso-8583-sink

二、App層App服務的開發和配置

對於Sink透傳App服務,只需要在app。yml中配置即可:

- app-service-id: /sink/iso-8583-sink type: sink-service sink-id: iso-8583-sink

可以看到在app。yml中,配置了App服務“/sink/iso-8583-sink”,型別為Sink透傳App服務(sink-service),透傳呼叫的Sink服務為“iso-8583-sink”。

三、啟動應用進行測試

啟動SampleSinkApplication、SampleAppApplication應用,透過OpenAPI介面進行測試:

$ curl -H “Content-Type:application/json” -H “Biz-Service-Id:/sink/iso-8583-sink” -X POST ——data ‘{“msgType”: “0800”,“reserved60”: “000000000030”,“card_accptr_id42”: “898411341310014”,“systemTraceAuditNumber11”: “000001”,“switching_data62”: “53657175656e6365204e6f3132333036303733373832323134”,“card_accptr_termnl_id41”: “73782214”,“msgHead”: “31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536”,“acct_id_1_102”: “1234567890”,“fin_net_data63”: “303031”}’ http://localhost:8888/api|jq{ “code”: 0, “message”: “success”, “extMessage”: null, “appServiceId”: “/sink/iso-8583-sink”, “traceId”: “9ffadf46d47849d2b353baec35d42ac7”, “parentTraceId”: null, “timestamp”: 1647176027306, “data”: { “msgType”: “0800”, “reserved60”: “000000000030”, “card_accptr_id42”: “898411341310014”, “systemTraceAuditNumber11”: “000001”, “switching_data62”: “53657175656e6365204e6f3132333036303733373832323134”, “card_accptr_termnl_id41”: “73782214”, “msgHead”: “31323031383430303031303334342020203432343330343430202020393031323334353637383930313233343536”, “acct_id_1_102”: “1234567890”, “fin_net_data63”: “303031” }}

EchoConnectorService列印日誌:

收到報文:

====+ 01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20 + ====== ASCII ====== +0000: 31 32 30 31 38 34 30 30 30 31 30 33 34 34 20 20 20 34 32 34 | 12018400010344 424 |0020: 33 30 34 34 30 20 20 20 39 30 31 32 33 34 35 36 37 38 39 30 | 30440 901234567890 |0040: 31 32 33 34 35 36 30 38 30 30 80 20 00 00 00 C0 00 16 00 00 | 1234560800� 。。。�。。。。 |0060: 00 00 04 00 00 00 30 30 30 30 30 31 37 33 37 38 32 32 31 34 | ……00000173782214 |0080: 38 39 38 34 31 31 33 34 31 33 31 30 30 31 34 30 31 32 30 30 | 89841134131001401200 |0100: 30 30 30 30 30 30 30 30 33 30 30 35 30 35 33 36 35 37 31 37 | 00000000300505365717 |0120: 35 36 35 36 65 36 33 36 35 32 30 34 65 36 66 33 31 33 32 33 | 5656e6365204e6f31323 |0140: 33 33 30 33 36 33 30 33 37 33 33 33 37 33 38 33 32 33 32 33 | 33036303733373832323 |0160: 31 33 34 30 30 36 33 30 33 30 33 31 31 30 31 32 33 34 35 36 | 13400630303110123456 |0180: 37 38 39 30 | 7890…………。。。。 |

Biz-SIP網站:

http://bizsip。bizmda。com

Gitee程式碼庫:

https://gitee。com/szhengye/biz-sip