walletCards

来自于:APICloud立即使用

add

概述

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

walletCards - 图1

注意

详细介绍可参考苹果开发者网站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文件

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

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

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

  1. {
  2. "barcode": {
  3. "messageEncoding": "iso-8859-1",
  4. "format": "PKBarcodeFormatPDF417",
  5. "message": "111"
  6. },
  7. "locations": [
  8. {
  9. "longitude": -122.3748889,
  10. "latitude": 37.6189722
  11. },
  12. {
  13. "longitude": -122.03118,
  14. "latitude": 37.33182
  15. }
  16. ],
  17. "passTypeIdentifier": "pass.com.APICloud.walletCards",
  18. "webServiceURL": "https://blog.csdn.net/sz_vcp2007/article/details/60762349",
  19. "formatVersion": 1,
  20. "relevantDate": "2018-12-08T13:00-08:00",
  21. "teamIdentifier": "6AYL20498Q",
  22. "authenticationToken": "bc83dde3304d766d5b1aea631827f84c",
  23. "description": "Boarding pass",
  24. "boardingPass": {
  25. "auxiliaryFields": [
  26. {
  27. "value": "22:30",
  28. "label": "BOARDS",
  29. "changeMessage": "Boarding time changed to %@.",
  30. "key": "boardingTime"
  31. },
  32. {
  33. "value": "LH451",
  34. "label": "FLIGHT",
  35. "changeMessage": "Flight number changed to %@",
  36. "key": "flightNewName"
  37. },
  38. {
  39. "value": "First",
  40. "label": "DESIG.",
  41. "key": "class"
  42. },
  43. {
  44. "value": "03/14",
  45. "label": "DATE",
  46. "key": "date"
  47. }
  48. ],
  49. "transitType": "PKTransitTypeAir",
  50. "secondaryFields": [
  51. {
  52. "value": "Johnny Appleseed",
  53. "label": "PASSENGER",
  54. "key": "passenger"
  55. }
  56. ],
  57. "primaryFields": [
  58. {
  59. "value": "SFO",
  60. "label": "SAN FRANCISCO",
  61. "key": "origin"
  62. },
  63. {
  64. "value": "JFK",
  65. "label": "NEW YORK",
  66. "key": "destination"
  67. }
  68. ],
  69. "backFields": [
  70. {
  71. "value": "USA",
  72. "label": "PASSPORT",
  73. "key": "passport"
  74. },
  75. {
  76. "value": "",
  77. "label": "TERMS",
  78. "key": "terms"
  79. }
  80. ],
  81. "headerFields": [
  82. {
  83. "value": "70",
  84. "label": "GATE",
  85. "changeMessage": "Gate changed to %@.",
  86. "key": "gate"
  87. }
  88. ]
  89. },
  90. "foregroundColor": "rgb(22, 55, 110)",
  91. "backgroundColor": "rgb(50, 91, 185)",
  92. "logoText": "Skyport Airways",
  93. "serialNumber": "sample",
  94. "organizationName": "Skyport Airways"
  95. }

add

添加卡片

add(params, callback(ret))

params

path:

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

callback(ret, err)

ret:

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

err:

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

示例代码

  1. var walletCards = api.require('walletCards');
  2. var params = {path:''};
  3. walletCards.add(params, function(ret, err) {
  4. if (ret.status) {
  5. api.alert({ msg:'添加成功'});
  6. } else {
  7. api.alert({ msg:JSON.stringify(err)});
  8. }
  9. });

可用性

iOS系统

可提供的1.0.0及更高版本