Apple Wallet Pass使用ColdFusion和Java

时间:2018-03-22 21:05:36

标签: coldfusion

我正在使用ColdFusion和Java的组合创建Apple Wallet Pass。我有一个创建通行证的cfc。它利用Java来签名和压缩传递。我在GitHub https://github.com/dawesi/cfwheels-passkithttps://github.com/drallgood/jpasskit

上使用这些项目

我在这里尝试创建一个传递:

    <cfset mypass = new passkit()>
    <cfset result = mypass.createPassbook()>

passkit.cfc

<cfcomponent displayname="Apple Passbook Plugin" output="false">
<cffunction name="init" output="false">
    <cfscript>
        this.version = "1.1.8";
        return this;
    </cfscript>
</cffunction>

<cffunction name="createPassbook" returntype="any" output="false">
    <cfargument name="type" type="string" default="generic"/>
    <cfscript>
        var loc = {};

        loc.returnValue = createObject('component','PassBook').init(arguments.type);

        return loc.returnValue;
    </cfscript>
</cffunction>

PassBook.cfc

   <cfcomponent displayname="Apple Passbook" output="false">
    <cffunction name="init" output="false">
        <cfargument name="type" type="string" default="generic"/>
        <cfscript>
            setType(arguments.type);
            return this;
        </cfscript>
    </cffunction>



     <cffunction name="build" returntype="any" output="false">
    <cfargument name="file" type="string" required="false"/>
    <cfargument name="password" type="string" default=""/>
    <cfscript>
        var loc = {};

        //Set things on the passbook at the end
        if(structKeyExists(variables,'barcode'))
            $getPassBook().setBarcode(variables.barcode);

        //Get the correct type that they set it too
        switch(variables.type){
            case 'boardingpass':
                loc.passClass = 'PKBoardingPass';
                loc.passMethod = 'setBoardingPass';
                break;
            case 'coupon':
                loc.passClass = 'PKCoupon';
                loc.passMethod = 'setCoupon';
                break;
            case 'eventticket':
                loc.passClass = 'PKEventTicket';
                loc.passMethod = 'setEventTicket';
                break;
            case 'storecard':
                loc.passClass = 'PKStoreCard';
                loc.passMethod = 'setStoreCard';
                break;
            default:
                loc.passClass = 'PKGenericPass';
                loc.passMethod = 'setGeneric';
                break;
        }

        //Create it, and add the fields
        loc.pass = $createJavaObject('de.brendamour.jpasskit.passes.#loc.passClass#');
        if(structKeyExists(variables,'fields')){
            for(loc.type in variables.fields){
                loc.method = variables.fields[loc.type].method;
                loc.fields = variables.fields[loc.type].fields;

                //loc.pass[loc.method](loc.fields);
                loc.dynamicMethod = loc.pass[loc.method]; // Get method
                loc.dynamicMethod(loc.fields); // Invoke it

        }

        //$getPassBook()[loc.passMethod](loc.pass);
        loc.dynamicMethod2 = $getPassBook()[loc.passMethod];
        loc.dynamicMethod2(loc.pass);



        //Sign and make the archive
        loc.signingUtil = $createJavaObject('de.brendamour.jpasskit.signing.PKSigningUtil');
        loc.signingInfo = loc.signingUtil.loadSigningInformationFromPKCS12FileAndIntermediateCertificateFile(
                $passBookCertificateLocation(),
                arguments.password,
                $intermediateCertificateLocation()
            );

        loc.bytes = loc.signingUtil.createSignedAndZippedPkPassArchive(
                $getPassBook(),
                variables.templatePath,
                loc.signingInfo
            );

        //See if we are writing this to a file
        if(structKeyExists(arguments,'file') && len(arguments.file)){
            loc.file = $createJavaObject('java.io.FileOutputStream').init(arguments.file);
            loc.file.write(loc.bytes);
            loc.file.close();
        }

        return loc.bytes;
    </cfscript>
</cffunction>


</cfcomponent>

但我遇到了这个错误。我认为它遗漏了一些东西。有人可以帮忙吗?

Invalid CFML construct found on line 354 at column 42.

ColdFusion was looking at the following text:
loc.method

The CFML compiler was processing:

A script statement beginning with loc.pass on line 354, column 33.
A script statement beginning with { on line 351, column 58.
A script statement beginning with for on line 351, column 25.
A script statement beginning with { on line 350, column 56.
A script statement beginning with if on line 350, column 17.
A cfscript tag beginning on line 317, column 10.
A cfscript tag beginning on line 317, column 10.

The error occurred in /Applications/ColdFusion2016/cfusion/wwwroot/passkit/PassBook.cfc: line 354
Called from /Applications/ColdFusion2016/cfusion/wwwroot/passkit/passkit.cfc: line 14
Called from /Applications/ColdFusion2016/cfusion/wwwroot/passkit/test_walletpass.cfm: line 7
352 :                   loc.method = variables.fields[loc.type].method;
353 :                   loc.fields = variables.fields[loc.type].fields;
354 :                   loc.pass[loc.method](loc.fields);
355 :               }

1 个答案:

答案 0 :(得分:1)

如果它不使用最新的CF,它可能包含特定于另一个引擎的语法,如Lucee。我没有回顾整件事,但我认为这就是它所抱怨的界限:

 loc.pass[loc.method](loc.fields);

AFAIK,Adobe的ColdFusion不支持这种动态方法调用。 This thread描述了可能解决限制的黑客攻击。基本上,将其分为两个动作。将方法引用存储在变量中。然后在该变量上调用该方法。例如:

loc.dynamicMethod = loc.pass[loc.method]; // Get method
loc.dynamicMethod(loc.fields); // Invoke it

// ... same issue a few lines down
//$getPassBook()[loc.passMethod](loc.pass);
loc.dynamicMethod = $getPassBook()[loc.passMethod];
loc.dynamicMethod(loc.pass);

请注意重要警告

  

我建议的方法的警告是它将方法拉出来   CFC,所以它将在调用代码的上下文中运行,   不是CFC实例。根据方法中的代码,这可能会   或者可能没关系。

没有使用该组件,无法说明它在这种情况下是否相关。