Skip to content

Commit 705054a

Browse files
author
yuqiuwen
committed
doc: 新增apple验签流程
1 parent 4d62ee9 commit 705054a

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

blog/2022-11-06-设计模式.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,4 @@ Floor: One | Size: Big and fancy
308308
### 访问者模式
309309

310310
### 模板方法模式
311+

blog/2022-12-24-leecode/LeetCode.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,36 @@ data = [
376376
```
377377

378378

379+
#### 最大数字组合
380+
> 有几个任意位数的正整数,求能组成的最大数字
381+
382+
思路:
383+
若 a+b > b+a,则a应该在前,否则a在后
384+
385+
```python
386+
from functools import cmp_to_key
387+
388+
def max_number(nums):
389+
# 自定义比较函数
390+
def compare(x, y):
391+
# 将两个字符串拼接起来进行比较
392+
return int(y + x) - int(x + y)
393+
394+
# 将正整数转换为字符串
395+
nums = [str(num) for num in nums]
396+
397+
# 使用自定义的比较函数对字符串进行排序
398+
nums.sort(key=cmp_to_key(compare))
399+
400+
# 将排序后的字符串连接起来得到最大数
401+
result = ''.join(nums)
402+
403+
return result
404+
405+
```
406+
407+
408+
379409

380410
## MySQL
381411

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Apple内购验签流程
3+
authors: Qiuwen
4+
description: ''
5+
tags: [订单系统, Apple内购]
6+
date: 2024-11-28 10:30:00
7+
---
8+
9+
**验证项:**
10+
针对旧版验证api:https://developer.apple.com/documentation/appstorereceipts/verifyreceipt
11+
为了验证收据伪造等情况,需验证以下几点:
12+
1. receipt.environment,区分订单环境(生产或沙盒),若返回21007表示沙盒环境,此时需用沙盒api再次验证https://sandbox.itunes.apple.com/verifyReceipt,方便客户端在生产环境进行测试而不用来回切换环境
13+
2. receipt.status == 0,为0表示有效
14+
3. order.product_id in product,系统中商品是否存在
15+
4. receipt.product_id == order.product_id,收据返回的商品id是否和订单的商品id一致
16+
5. receipt.bundle_id == product.bundle_id,不同bundle_id之间的product_id可能重复,若有多个包,系统可单独管理内购商品,此时订单中的product_id应该为product表的主键id
17+
6. receipt.transaction_id,检查商户id是否已存在于订单记录中,若存在表示已验签,可将 (pay_type, transaction_id) 作为联合唯一索引
18+
7. receipt.cancellation_date,如果receipt中包含cancellation_date属性,说明交易被取消或退款
19+
8. order.ctime < receipt.purchase_date_ms,正常情况应该是下单时间小于收据中的购买时间,前提是系统时间order.ctime准确无误
20+
21+
22+
23+
**流程图:**
24+
25+
26+
27+
```mermaid
28+
sequenceDiagram
29+
actor Client
30+
participant Server
31+
participant Apple Server
32+
participant MQ
33+
34+
35+
Client ->> Server: query product info
36+
Server ->> Client: return product
37+
Client ->>+ Server: request orderId
38+
Server ->> Server: create order
39+
Server ->> MQ: send delay message (check order state after 15 min)
40+
Server ->>- Client: return orderId
41+
Client ->>+ Apple Server: pay
42+
Apple Server ->>- Client: return receipt
43+
Client ->>+ Server: verify
44+
Server ->> Server: query order
45+
46+
alt not exists ?
47+
Server ->> Client: return error
48+
else exists
49+
Server ->>- Apple Server: verify receipt
50+
Apple Server ->> Server: return result
51+
alt passed
52+
Server ->> Client: return success
53+
else else
54+
Server ->> Client: return failed
55+
end
56+
end
57+
58+
MQ ->>+ Server: deliver message
59+
Server ->> Server: check order state
60+
alt unpaid
61+
Server ->>- Server: marked as canceled
62+
end
63+
64+
65+
```

test.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,45 @@ sequenceDiagram
1010
Server ->> Client: custom token
1111
Client ->> Client: storage token
1212
Client ->> Server: send request with token
13+
```
14+
15+
16+
17+
```mermaid
18+
sequenceDiagram
19+
actor Spider
20+
participant 计算中心
21+
participant 巡检中心
22+
participant 退款服务
23+
participant DB
24+
25+
Note over Spider: 启动
26+
Spider->>Spider: 扒取比赛数据
27+
Spider->>DB: 持久化存储
28+
29+
计算中心->>DB: 计算并更新开奖结果
30+
计算中心->>DB: 计算并更新方案结果
31+
计算中心->>DB: 计算并更新专家胜率
32+
alt 有异常比赛
33+
计算中心->>退款服务: 退款处理
34+
计算中心->>DB: 下架方案
35+
end
36+
alt 不中可退类型
37+
计算中心->>退款服务: 退款处理
38+
end
39+
40+
loop 1次/30min
41+
巡检中心->>DB: 巡检异常比赛
42+
alt 存在异常比赛(腰斩中断等)
43+
巡检中心->>DB: 更新比赛状态为 `unknown`
44+
巡检中心->>DB: 更新相关方案的订单状态为 `待退款`
45+
end
46+
end
47+
48+
loop 1次/6h
49+
巡检中心->>DB: 查询订单数据
50+
alt 存在待退款订单
51+
巡检中心->>退款服务: 退款处理
52+
end
53+
end
1354
```

0 commit comments

Comments
 (0)