将PHP代码转换为ColdFusion代码

时间:2017-03-15 12:52:40

标签: php api soap coldfusion

我需要将这段代码从PHP转换为ColdFusion。

PHP

 $mothodOption = array(
'apiUsername' => 'username11',
'apiPassword'  => 'password11',
'SchoolID' => 32923,
'FirstName'  => 'Mensaboy',
'LastName'  => 'Superfamily',
'RequestedUsername'  => '3537807',
'Password'  => 'Password123!',
'StudentExternalID'  => '3537807',
'Email'  => 'test@test.com',
'Street'  => '334 Second Street',
'City'  => 'Catasauqua',
'Zip'  => '18032',
'State'  => 'TX',
'HomePhone'  => '333-555-6666',
'AltPhone'  => '222-333-4444',
'GradeLevel'  => 3,
'BirthDate'  => strtotime(date("Y-m-d H:i:s")),
'StudentGender'  => "Female",
'Notes'  => 'Some Notes'
);

$client = new SoapClient("example.com");
$response = $client->__soapCall('CreateStudentWithUsername', array('parameters' => $mothodOption));

上面的代码工作正常,现在这里是我尝试过的Cold Fusion代码:

<CFSET unix_time = DateDiff("s", CreateDate(1970,1,1), Now()) />
<cfscript>
ws = createObject("webservice", "#APIurl#");

args = {
        apiUsername="username11"
        ,apiPassword="password11"
        ,SchoolID="32923"
        ,FirstName="Mensaboy"
        ,LastName="Superfamily"
        ,RequestedUsername="3537807"
        ,Password="Password123!"
        ,StudentExternalID="3537807"
        ,Email="test@test.com"
        ,Street="334 Second Street"
        ,City="Catasauqua"
        ,Zip="18032"
        ,State="TX"
        ,HomePhone="333-555-6666"
        ,AltPhone="222-333-4444"
        ,GradeLevel="3"
        ,BirthDate="#unix_time#"
        ,StudentGender="Female"
        ,Notes="Some Notes"
    };

result  = ws.CreateStudentWithUsername(argumentCollection=args);
writeDump(result);
</cfscript>

当我运行上面的代码时,我收到一个错误:

 Web service operation CreateStudentWithUsername with parameters {...} cannot be found.

这些是我需要发送的参数:

<xs:element name="CreateStudentWithUsername">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="apiUsername" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="apiPassword" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="SchoolID" type="xs:int"/>
<xs:element minOccurs="0" name="FirstName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="LastName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="RequestedUsername" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Password" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="StudentExternalID" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Email" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Street" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="City" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Zip" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="State" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="HomePhone" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="AltPhone" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="GradeLevel" type="xs:int"/>
<xs:element minOccurs="0" name="BirthDate" type="xs:dateTime"/>
<xs:element xmlns:q18="http://schemas.datacontract.org/2004/07/Enumerations" minOccurs="0" name="StudentGender" type="q18:Gender"/>
<xs:element minOccurs="0" name="Notes" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试使用CFHTTP或CFINVOKE,如下所示:

<cfhttp url="https://www.example.com/CreateStudentWithUsername" method="post" result="result" charset="utf-8"> 
    <cfhttpparam type="formfield" name="apiUsername" value="username11"> 
    <cfhttpparam type="formfield" name="apiPassword" value="password11"> 
    <cfhttpparam type="formfield" name="SchoolID" value="32923"> 
    .....
    .....
    .....
    so on...
</cfhttp> 


<cfinvoke webservice = "https://www.example.com"  method = "CreateStudentWithUsername"  returnVariable = "result">

    <cfinvokeargument name="apiUsername" value="username11" >
    <cfinvokeargument name="apiPassword" value="password11" >
    <cfinvokeargument name="SchoolID" value="32923" >
    <cfinvokeargument name="FirstName" value="Mensaboy" >
    .....
    .....
    .....
    so on...
</cfinvoke>