九月丶

PHP使用SOAP扩展访问webservice的实现
sdfsafs之前做的一个功能,折腾了很久才弄出来的,记录一下。public function insurance...
扫描右侧二维码阅读全文
06
2018/01

PHP使用SOAP扩展访问webservice的实现

sdfsafs
之前做的一个功能,折腾了很久才弄出来的,记录一下。

public function insurance(){
    header("content-type:text/html;charset=gb2312");
    
    $xmlStr1 = '<Packet type="REQUEST" version="1.0">
    <Head>
        <TransType>B0101</TransType>
        <TransID>PTRVACCZK_B2C17000000000001</TransID>
        <TransDate>2017-08-01 11:34:38</TransDate>
        <RequestType>02</RequestType>
        <User>YBY_PROD</User>
        <Password>fnkal58202</Password>
    </Head>
    <Body>
        <BasePart>
            <ProposalNo></ProposalNo>
            <OrderNo>PTRVACCZK_B2C270044654652120081</OrderNo>
            <BusinessNature>8</BusinessNature>
            <BusinessType>02</BusinessType>
            <Category>TRV_ACC_DOM</Category>
            <SumAmount>110000</SumAmount>
            <SumPremium>2.8</SumPremium>
            <SumQuantity>1</SumQuantity>
            <RiskCode>1115</RiskCode>
            <GoalInsuredFlag>0</GoalInsuredFlag>
            <AutoTransRenewFlag>99</AutoTransRenewFlag>
            <ShareHolderFlag>0</ShareHolderFlag>
            <ArgueSolution>1</ArgueSolution>
            <ArbitBoardName/>
            <StartDate>2017-08-24 00:00:00</StartDate>
            <StartHour>0</StartHour>
            <EndDate>2018-08-23 23:59:59</EndDate>
            <EndHour>24</EndHour>
            <OperatorCode>W35023001</OperatorCode>
            <MakeCom>2350200501</MakeCom>
            <InputDate>2017-08-02</InputDate>
            <ComCode>2350200501</ComCode>
            <Handler1Code>W35023001</Handler1Code>
            <PhoneType>15</PhoneType>
            <IntroducePhone></IntroducePhone>
            <PdfType>1115A</PdfType>
            <WXTransNo></WXTransNo>
            <WXTransType></WXTransType>
            <PbSourceType></PbSourceType>
            <AgentCode>U600010000405</AgentCode>
            <AgreementNo>U600010000405-01</AgreementNo>
        </BasePart>
        <InsuredList>
            <InsuredData>
                <InsuredType>1</InsuredType>
                <InsuredFlag>2</InsuredFlag>
                <InsuredIdentity>01</InsuredIdentity>
                <InsuredNature>3</InsuredNature>
                <IdentifyType>01</IdentifyType>
                <IdentifyNumber>140107200701012619</IdentifyNumber>
                <InsuredName>小夏夏</InsuredName>
                <Sex>1</Sex>
                <Age>10</Age>
                <Occupation>1</Occupation>
                <Birthday>2007-01-01</Birthday>
                <SalfMobile>13651707372</SalfMobile>
                <Mobile>13651707372</Mobile>
                <Email>516093548@qq.com</Email>
                <RiskLevel>4</RiskLevel>
                <Reserved2>1</Reserved2>
            </InsuredData>
            <InsuredData>
                <InsuredType>1</InsuredType>
                <InsuredFlag>1</InsuredFlag>
                <InsuredNature>3</InsuredNature>
                <IdentifyType>01</IdentifyType>
                <IdentifyNumber>140107200701012619</IdentifyNumber>
                <InsuredName>小夏夏</InsuredName>
                <Sex>1</Sex>
                <Age>10</Age>
                <Occupation>1</Occupation>
                <Birthday>2007-01-01</Birthday>
                <SalfMobile>13651707372</SalfMobile>
                <Mobile>13651707372</Mobile>
                <Email>516093548@qq.com</Email>
                <RiskLevel>4</RiskLevel>
                <Reserved2>1</Reserved2>
            </InsuredData>
        </InsuredList>
        <MainConstructData>
            <ConstructName>祖国建设大业</ConstructName>
            <ConstructType>070201</ConstructType>
            <BusinessSource>3</BusinessSource>
            <PossessNature>0002</PossessNature>
            <ProjectKind>01</ProjectKind>
            <Qualification>01</Qualification>
            <CertificateGrade>02</CertificateGrade>
            <ProjectContractNo>123456789</ProjectContractNo>
            <AnticipatedPrice>120000</AnticipatedPrice>
            <TenderFileNo>1233211</TenderFileNo>
            <StartFixDate>2010-10-08</StartFixDate>
            <EndFixDate>2019-10-09</EndFixDate>
        </MainConstructData>
        <CounterMeasureData>
            <DepositSum>130000</DepositSum>
            <ImportAccount>340*********</ImportAccount>
            <CouMeaType>0001</CouMeaType>
            <NameType>0001</NameType>
            <Name>反制措施名称</Name>
            <ContraType>0001</ContraType>
            <ContracNumber>109879812312</ContracNumber>
            <SumType>0001</SumType>
            <Sum>1400000</Sum>
            <MortgageScale>10</MortgageScale>
            <SponsorCredentials>11</SponsorCredentials>
            <SponsorCredID>12</SponsorCredID>
        </CounterMeasureData>
        <ItemKindAddressList>
            <ItemKindAddressData>
                <AddressNo>1</AddressNo>
                <AddressCode>12345</AddressCode>
                <AddressName>啊实打实大师大师的</AddressName>
            </ItemKindAddressData>
       </ItemKindAddressList>

        <ItemKindList>
            <ItemKindData>
                <KindCode>001</KindCode>
                <KindName>投标保证保险金额(中标后转入履约保证保险金额的一部分)</KindName>
                <ItemCode>0001</ItemCode>
                <ItemDetailName>投标保证保险金额(中标后转入履约保证保险金额的一部分)</ItemDetailName>
                <AddressNo>1</AddressNo>
                <UnitAmount>100000</UnitAmount>
                <Currency>CNY</Currency>
                <Rate>1.0000</Rate>
                <Discount>100</Discount>
                <UnitPremium>1.8</UnitPremium>
                <ShortRateFlag>3</ShortRateFlag>
                <ShortRate>100</ShortRate>
                <DeductibleRate>100</DeductibleRate>
                <Deductible>0</Deductible>
                <ProportionMain>1</ProportionMain>
            </ItemKindData>
            <ItemKindData>
                <KindCode>002</KindCode>
                <KindName>履约保证保险金额(包含中标后转入的投标保证保险金额)</KindName>
                <ItemCode>0002</ItemCode>
                <ItemDetailName>履约保证保险金额(包含中标后转入的投标保证保险金额)</ItemDetailName>
                <AddressNo>1</AddressNo>
                <UnitAmount>10000</UnitAmount>
                <Currency>CNY</Currency>
                <Rate>1.0000</Rate>
                <Discount>100</Discount>
                <UnitPremium>1</UnitPremium>
                <ShortRateFlag>3</ShortRateFlag>
                <ShortRate>100</ShortRate>
                <DeductibleRate>90</DeductibleRate>
                <Deductible>100</Deductible>
                <ProportionMain>1</ProportionMain>
            </ItemKindData>
        </ItemKindList>
        <PlanList>
            <PlanData>
                <SerialNo>1</SerialNo>
                <PlanStartDate>2017-08-01</PlanStartDate>
                <PlanDate>2017-08-01</PlanDate>
                <Curreny>CNY</Curreny>
                <PlanFee>2.8</PlanFee>
            </PlanData>
        </PlanList>
        <EngageList>
            <EngageData>
                <ClauseCode>T9999</ClauseCode>
                <ClauseName>其他</ClauseName>
                <Clauses>1、投保时被保险人的年龄应在1-75周岁(含)之间。2、被保险人从事潜水、跳伞、攀岩运动、探险活动、武术比赛、摔跤比赛、特技表演、赛马、赛车等高风险运动时,不属于本保险责任范畴。3、每次事故意外伤害医疗费用超过人民币100元部分,按90%的比例给付意外伤害医疗保险金。4、被保险人为未成年人的,其保险金额超出中国保监会最高保额限制的,赔付时按照中国保险监督管理委员会规定的未成年人最高保额限制赔付。5、其他未尽事宜以紫金财产保险股份有限公司《旅游意外伤害保险条款》为准。</Clauses>
            </EngageData>
        </EngageList>
    </Body></Packet>';


    try {
            $client = new \SoapClient("http://IP地址:端口号/prpall/services/EServerManage?wsdl");

            $client->soap_defencoding = 'gb2312';
            $client->xml_encoding = 'gb2312';

            $xmlStr = array( array('xmlStr' => $xmlStr1) );

            $arr1 = $client->__soapCall('getServerXML', $xmlStr);

        } catch (SOAPFault $e) {
            print $e;
        }


}

有三点需要特别注意一下。

  • 需要安装php的soap扩展,扩展装完直接引用即可。
  • $xmlStr = array( array('xmlStr' => $xmlStr1) );

注:这一行代码需要特别注意一下,当时就是这里卡了我好几天,对方一直说没有连接成功,后来才发现其实已经连接成功了,只是没有接受到参数(我欲哭无泪啊)。网上找的都是一维数组,这里要用二维数组才行,还不清楚原因,反正他们是能接受到参数了。当时感动的我都快哭了。
还有一点特别要注意,这个参数名一定要跟提供方接受的参数名称保持一致,否则对方无法接受到参数

  • $arr1 = $client->__soapCall('getServerXML', $xmlStr);

注:这个方法第一个参数就是对方提供的方法名称,第二个参数是对方接收的参数值。

最后修改:2018 年 04 月 10 日 11 : 42 AM
如果觉得我的文章对你有用,请随意赞赏

1 条评论

  1. 123

    你好

发表评论