Skip to content

Instantly share code, notes, and snippets.

@onevcat
Created March 17, 2017 04:33
Show Gist options
  • Save onevcat/f0ef55b3d4a04c6e3f89f77301a61824 to your computer and use it in GitHub Desktop.
Save onevcat/f0ef55b3d4a04c6e3f89f77301a61824 to your computer and use it in GitHub Desktop.

Entry point:

https://store.objccn.io/api/v1/redeem/

POST

application/json

Parameter:

  • api_key (required):
  • email (required): 用户的邮箱,将作为在 ObjCCN 的用户凭证
  • security_hash (required):验证请求有效性的 hash,请设置为 md5(email + product_name + private_key)
  • product_name (required):functional-swift|advanced-swift|core-date|swifter-tips 任选其一
  • user_first_name (optional):用户名字
  • user_last_name (optional):用户姓

api_key 和 private_key 将在 API 创建时发送给您

Return:

  • 成功例
{
   "result": {
       "CustomerEmail": "onevcat@gmail.com",
       "CustomerFirstName": "",
       "CustomerLastName": "",
       "ItemDiscount": 0,
       "ItemPrice": 0,
       "OrderID": "xxxx-06330196-b84b-4b3e-a599-0fbc9e492e30", (其中xxxx是服务名)
       "ProductName": "functional-swift"
   }
}
  • 失败例
{
   "error": {
       "code": 10001,
       "message": "参数不全。"
   }
}

说明

user_first_nameuser_last_name 是我们用来管理订单用户信息的,可以作为之后的验证手段。如果 API 使用方没有收集这个信息,不发这两个参数也没问题。

请将用户的 emailproduct_nameprivate_key 拼接以后做一个 md5 发过来,ObjCCN 会根据这个对请求进行简单的验证。

错误代码还有一些其他的类型,但是出错的话一定是 200 状态码加上一个包含 error 的 JSON。成功的时候会有一个 result,里面包含 OrderID 可以作为订单凭证,看你们是否需要保存以后用之类的。注意成功的时候返回的 JSON 不包含 error 键。

最常见的 error 有可能是 “30001 该账号已经购买过此产品”。这表示该邮箱已经在之前就购买过这本书了。怎么处理的话就看你们了。 上面的 Entry point 是产品服务器,不过因为这个 API 比较简单,应该问题不大。ObjCCN 有一个测试服务器,但是因为是外网,所以平时也不开。如果你们需要上线前测试一下的话,可以联系我,我去把测试服务器跑起来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment