使用ColdFusion和Java的Apple Wallet Pass



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

在这里,我正在尝试创建一个通行证:

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

The 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>

存折

   <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 :               }

如果它不适用于最新的 CF,则可能包含特定于其他引擎(如 Lucee(的语法。我没有审查整个事情,但我认为这是它抱怨的那句话:

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

AFAIK,Adobe的ColdFusion不支持这种动态方法调用。此线程描述了可能绕过限制的黑客。基本上,将其分为两个操作。将方法引用存储在变量中。然后对该变量调用该方法。例:

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 实例。根据方法中的代码,这可能会 或者可能无关紧要。

没有使用过该组件,无法说明它是否与此方案相关。

最新更新