walletCards

来自于:APICloud立即使用

add

概述

本模块可向钱包中添加消费券、优惠券、火车机票等,卡片可服务器端制作,也可本地制作。

注意

详细介绍可参考苹果开发者网站walletCards相关详细流程

本地制作PKPass文件

不明之处可参考苹果开发者网站walletCards文件制作流程

  1. 苹果开发者网站申请Pass Type id,并且生成对应的证书

  2. 创建pass.json文件

  3. 配置pass.json,passTypeIdentifier和teamIdentifier,前者就是上面在开发者中心创建的Pass Type ID(例如:”pass.com.taokatao.mywallet“),后者是对应的团队标识,申请苹果开发者账号时会分配一个唯一的团队标识(可以在苹果开发者中心–查看账户信息中查看”Team ID“)。其他信息根据实际情况配置。

  1. 在桌面创建Lollipop.pass(pass是文件夹的扩展名)和app文件夹,将Lollipop.pass复制到app文件夹中,将pass.json文件复制到Lollipop.pass文件夹中

  2. 下载 signpass可执行文件并复制到app文件夹中

  3. 准备icon、logo和strip三类图片复制到Lollipop.pass文件夹中(其他类型图片有需要请参考 苹果开发者网站-Pass Design and Creation

  4. 在终端中执行以下命令得倒.pkpass文件

    cd ~/Desktop/app
    ./signpass -p Lollipop.pass

卡片类型配置及内容介绍请参考苹果开发者网站

pass.json文件示例内容如下:

    {
  "barcode": {
    "messageEncoding": "iso-8859-1",
    "format": "PKBarcodeFormatPDF417",
    "message": "111"
  },
  "locations": [
    {
      "longitude": -122.3748889,
      "latitude": 37.6189722
    },
    {
      "longitude": -122.03118,
      "latitude": 37.33182
    }
  ],
  "passTypeIdentifier": "pass.com.APICloud.walletCards",
  "webServiceURL": "https://blog.csdn.net/sz_vcp2007/article/details/60762349",
  "formatVersion": 1,
  "relevantDate": "2018-12-08T13:00-08:00",
  "teamIdentifier": "6AYL20498Q",
  "authenticationToken": "bc83dde3304d766d5b1aea631827f84c",
  "description": "Boarding pass",
  "boardingPass": {
    "auxiliaryFields": [
      {
        "value": "22:30",
        "label": "BOARDS",
        "changeMessage": "Boarding time changed to %@.",
        "key": "boardingTime"
      },
      {
        "value": "LH451",
        "label": "FLIGHT",
        "changeMessage": "Flight number changed to %@",
        "key": "flightNewName"
      },
      {
        "value": "First",
        "label": "DESIG.",
        "key": "class"
      },
      {
        "value": "03/14",
        "label": "DATE",
        "key": "date"
      }
    ],
    "transitType": "PKTransitTypeAir",
    "secondaryFields": [
      {
        "value": "Johnny Appleseed",
        "label": "PASSENGER",
        "key": "passenger"
      }
    ],
    "primaryFields": [
      {
        "value": "SFO",
        "label": "SAN FRANCISCO",
        "key": "origin"
      },
      {
        "value": "JFK",
        "label": "NEW YORK",
        "key": "destination"
      }
    ],
    "backFields": [
      {
        "value": "USA",
        "label": "PASSPORT",
        "key": "passport"
      },
      {
        "value": "",
        "label": "TERMS",
        "key": "terms"
      }
    ],
    "headerFields": [
      {
        "value": "70",
        "label": "GATE",
        "changeMessage": "Gate changed to %@.",
        "key": "gate"
      }
    ]
  },
  "foregroundColor": "rgb(22, 55, 110)",
  "backgroundColor": "rgb(50, 91, 185)",
  "logoText": "Skyport Airways",
  "serialNumber": "sample",
  "organizationName": "Skyport Airways"
}

add

添加卡片

add(params, callback(ret))

params

path:

  • 类型:字符串
  • 描述:PKPass文件路径;支持fs,widget

callback(ret, err)

ret:

  • 类型:JSON对象
  • 描述:添加结果;
  • 内部字段:
{
     status:true  //布尔类型;是否添加成功,true|false
}

err:

  • 类型:JSON对象
  • 描述:添加错误信息;
  • 内部字段:
{
     msg: ''            //字符串类型;错误信息
}

示例代码

var walletCards = api.require('walletCards');
var params = {path:''};
walletCards.add(params, function(ret, err) {
     if (ret.status) {
        api.alert({ msg:'添加成功'});
    } else {
        api.alert({ msg:JSON.stringify(err)});
    }
});

可用性

iOS系统

可提供的1.0.0及更高版本