<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <s:server-script><![CDATA[
            importPackage(Packages.com.hand.hls.hlcm.ccx.service);
            var service = $spring(ICcxIdentityService);

            // 配置信息
            var interface_code = 'CCX_NP_INTERFACE';
            var interface_parameter_bm = $bm('interface.hls_interface_parameter');
            var interface_parameter_result = interface_parameter_bm.queryAsMap({
                "interface_code": interface_code
            });
            var interface_parameter_records = interface_parameter_result.getChildren();

            var apiUrl = interface_parameter_records[0].INTERFACE_URL; //环境地址
            var account = interface_parameter_records[0].INTERFACE_USERNAME;  //用户名
            var privateKey = interface_parameter_records[0].INTERFACE_PASSWORD;  //密码

            //var apiUrl = 'https://tapi.ccxcredit.com/data-service/identity/auth';
            //var account = 'DCFL0011';
            //var privateKey = '0c95ab2ec86a4a018f77eb56d7ed26e7';
                // 测试数据
                //var cid = '123456199001011233';
                //var name = '张三';
                var cid = $ctx.parameter.id_card_no;
                var name = $ctx.parameter.bp_name;
                try {
                    //发起请求
                    var resultString = service.sendCcxIdentityMessage(apiUrl, account, privateKey, cid, name);
                    println(resultString);
                    //转成json数组
                    var result = JSON.parse(resultString);
                    println("對象:"+result);
                    //获取返回的验证消息resMsg
                    var resCode = result.resCode;
                    var resMsg = result.resMsg;
                    var tid = result.tid;
                    var sign = result.sign;
                    println("信息:"+resMsg);
                } catch (e) {
                    raise_app_error("抛出异常:" + e);
                }

                $ctx.parameter.resmsg = resMsg;

                 // 发送请求后,逻辑处理
                $bm('interface.CCX_INTERFACE.hls_ccx_interface').update({
                    bp_id: $ctx.parameter.bp_id,
                    bp_name:name,
                    id_card_no:cid,
                    resCode: resCode,
                    resMsg: resMsg,
                    tid:tid,
                    sign:sign
                });
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>