cgserver 12.0.8 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +9 -0
  2. package/dist/lib/Framework/AI/AiObject.js +10 -10
  3. package/dist/lib/Framework/AI/Astar.js +133 -133
  4. package/dist/lib/Framework/AI/BehaviorAI.js +340 -307
  5. package/dist/lib/Framework/AI/Entity.js +33 -33
  6. package/dist/lib/Framework/AI/Point.js +68 -68
  7. package/dist/lib/Framework/AI/TriggerMgr.js +201 -201
  8. package/dist/lib/Framework/Config/Config.js +74 -41
  9. package/dist/lib/Framework/Config/DbConfig.js +14 -14
  10. package/dist/lib/Framework/Config/FrameworkConfig.js +139 -173
  11. package/dist/lib/Framework/Config/IServerConfig.js +31 -31
  12. package/dist/lib/Framework/Config/_error_.js +35 -35
  13. package/dist/lib/Framework/Core/ByteTool.js +85 -85
  14. package/dist/lib/Framework/Core/Core.js +724 -688
  15. package/dist/lib/Framework/Core/Timer.js +116 -116
  16. package/dist/lib/Framework/Database/Decorator/AutoIncrement.js +10 -11
  17. package/dist/lib/Framework/Database/Decorator/DBCache.js +98 -65
  18. package/dist/lib/Framework/Database/Decorator/NotNull.js +10 -11
  19. package/dist/lib/Framework/Database/Decorator/PrimaryKey.js +10 -11
  20. package/dist/lib/Framework/Database/Decorator/Property.js +61 -61
  21. package/dist/lib/Framework/Database/Decorator/Table.js +14 -15
  22. package/dist/lib/Framework/Database/Decorator/Type.js +19 -20
  23. package/dist/lib/Framework/Database/MSSql/MSSqlManager.js +86 -53
  24. package/dist/lib/Framework/Database/Mongo/MongoBaseService.js +141 -141
  25. package/dist/lib/Framework/Database/Mongo/MongoManager.js +595 -547
  26. package/dist/lib/Framework/Database/Mongo/MongoServiceManager.js +52 -52
  27. package/dist/lib/Framework/Database/Mysql/MysqlBaseService.js +280 -280
  28. package/dist/lib/Framework/Database/Mysql/MysqlManager.js +138 -105
  29. package/dist/lib/Framework/Database/Redis/RedisManager.js +94 -61
  30. package/dist/lib/Framework/Decorator/AdminValidate.js +18 -19
  31. package/dist/lib/Framework/Decorator/AuthorityValidate.js +22 -22
  32. package/dist/lib/Framework/Decorator/CreatorValidate.js +18 -19
  33. package/dist/lib/Framework/Decorator/JsonAdminValidate.js +14 -15
  34. package/dist/lib/Framework/Decorator/JsonAuthorityValidate.js +20 -20
  35. package/dist/lib/Framework/Decorator/JsonCreatorValidate.js +18 -19
  36. package/dist/lib/Framework/Decorator/SyncCall.js +41 -42
  37. package/dist/lib/Framework/Decorator/SyncCallServer.js +77 -77
  38. package/dist/lib/Framework/Logic/CacheTool.js +106 -73
  39. package/dist/lib/Framework/Logic/EventTool.js +31 -28
  40. package/dist/lib/Framework/Logic/HttpTool.js +138 -105
  41. package/dist/lib/Framework/Logic/Log.js +121 -88
  42. package/dist/lib/Framework/Logic/SyncQueueTool.js +44 -44
  43. package/dist/lib/Framework/Server/ProtoFilter/GoogleProtoFilter.js +90 -57
  44. package/dist/lib/Framework/Server/ProtoFilter/IProtoFilter.js +9 -9
  45. package/dist/lib/Framework/Server/ProtoFilter/JsonProtoFilter.js +29 -29
  46. package/dist/lib/Framework/Server/ProtoFilter/ProtoFactory.js +35 -35
  47. package/dist/lib/Framework/Server/RpcWebSocketServer/CgMq.js +180 -180
  48. package/dist/lib/Framework/Server/RpcWebSocketServer/IRpc.js +38 -38
  49. package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.js +253 -253
  50. package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcServerWebSocket.js +94 -94
  51. package/dist/lib/Framework/Server/SocketServer/IClientSocket.js +44 -44
  52. package/dist/lib/Framework/Server/SocketServer/IServerSocket.js +114 -81
  53. package/dist/lib/Framework/Server/SocketServer/ISocket.js +255 -222
  54. package/dist/lib/Framework/Server/SocketServer/ISocketServer.js +177 -144
  55. package/dist/lib/Framework/Server/SocketServer/PacketParser.js +40 -40
  56. package/dist/lib/Framework/Server/WebServer/Controller/BaseController.js +119 -119
  57. package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +171 -171
  58. package/dist/lib/Framework/Server/WebServer/Controller/MysqlBaseUserController.js +169 -169
  59. package/dist/lib/Framework/Server/WebServer/Engine/ControllerManager.js +115 -115
  60. package/dist/lib/Framework/Server/WebServer/Engine/Engine.js +254 -218
  61. package/dist/lib/Framework/Server/WebServer/Engine/RazorJs.js +543 -543
  62. package/dist/lib/Framework/Server/WebServer/Engine/Request.js +226 -226
  63. package/dist/lib/Framework/Server/WebServer/Engine/Response.js +120 -87
  64. package/dist/lib/Framework/Server/WebServer/IWebServer.js +55 -55
  65. package/dist/lib/Framework/Server/WebSocketServer/IClientWebSocket.js +44 -44
  66. package/dist/lib/Framework/Server/WebSocketServer/IServerWebSocket.js +128 -95
  67. package/dist/lib/Framework/Server/WebSocketServer/IWebSocket.js +248 -215
  68. package/dist/lib/Framework/Server/WebSocketServer/IWebSocketServer.js +250 -217
  69. package/dist/lib/Framework/Service/MongoAccountService.js +339 -339
  70. package/dist/lib/Framework/Service/MongoCacheService.js +50 -50
  71. package/dist/lib/Framework/Service/MongoUserService.js +129 -96
  72. package/dist/lib/Framework/Service/MysqlAccountService.js +411 -411
  73. package/dist/lib/Framework/Service/MysqlUserService.js +204 -171
  74. package/dist/lib/Framework/Service/ini.js +36 -36
  75. package/dist/lib/Framework/ThirdParty/AlipayTool.js +117 -205
  76. package/dist/lib/Framework/ThirdParty/Alisms.js +61 -50
  77. package/dist/lib/Framework/ThirdParty/AppleTool.js +271 -235
  78. package/dist/lib/Framework/ThirdParty/CgRankTool.js +215 -215
  79. package/dist/lib/Framework/ThirdParty/EmailTool.js +71 -38
  80. package/dist/lib/Framework/ThirdParty/QQTool.js +162 -129
  81. package/dist/lib/Framework/ThirdParty/QiniuTool.js +62 -29
  82. package/dist/lib/Framework/ThirdParty/Rpc.js +79 -79
  83. package/dist/lib/Framework/ThirdParty/WechatTool.js +167 -134
  84. package/dist/lib/Framework/cgserver.js +215 -212
  85. package/dist/lib/Framework/global.js +74 -74
  86. package/dist/lib/Framework/index.js +38 -5
  87. package/dist/lib/Framework/index_export_.js +180 -177
  88. package/dist/lib/test/test.js +21 -21
  89. package/dist/types/Framework/AI/AiObject.d.ts +5 -5
  90. package/dist/types/Framework/AI/Astar.d.ts +38 -38
  91. package/dist/types/Framework/AI/BehaviorAI.d.ts +24 -24
  92. package/dist/types/Framework/AI/Entity.d.ts +12 -12
  93. package/dist/types/Framework/AI/Point.d.ts +17 -17
  94. package/dist/types/Framework/AI/TriggerMgr.d.ts +51 -51
  95. package/dist/types/Framework/Config/Config.d.ts +9 -9
  96. package/dist/types/Framework/Config/DbConfig.d.ts +11 -11
  97. package/dist/types/Framework/Config/FrameworkConfig.d.ts +146 -178
  98. package/dist/types/Framework/Config/IServerConfig.d.ts +9 -9
  99. package/dist/types/Framework/Config/_error_.d.ts +99 -99
  100. package/dist/types/Framework/Core/ByteTool.d.ts +21 -21
  101. package/dist/types/Framework/Core/Core.d.ts +119 -120
  102. package/dist/types/Framework/Core/Timer.d.ts +16 -16
  103. package/dist/types/Framework/Database/Decorator/AutoIncrement.d.ts +1 -1
  104. package/dist/types/Framework/Database/Decorator/DBCache.d.ts +22 -22
  105. package/dist/types/Framework/Database/Decorator/NotNull.d.ts +1 -1
  106. package/dist/types/Framework/Database/Decorator/PrimaryKey.d.ts +1 -1
  107. package/dist/types/Framework/Database/Decorator/Property.d.ts +57 -57
  108. package/dist/types/Framework/Database/Decorator/Table.d.ts +1 -1
  109. package/dist/types/Framework/Database/Decorator/Type.d.ts +1 -1
  110. package/dist/types/Framework/Database/MSSql/MSSqlManager.d.ts +26 -26
  111. package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +116 -116
  112. package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +207 -204
  113. package/dist/types/Framework/Database/Mongo/MongoServiceManager.d.ts +13 -13
  114. package/dist/types/Framework/Database/Mysql/MysqlBaseService.d.ts +34 -34
  115. package/dist/types/Framework/Database/Mysql/MysqlManager.d.ts +30 -30
  116. package/dist/types/Framework/Database/Redis/RedisManager.d.ts +24 -24
  117. package/dist/types/Framework/Decorator/AdminValidate.d.ts +1 -1
  118. package/dist/types/Framework/Decorator/AuthorityValidate.d.ts +2 -2
  119. package/dist/types/Framework/Decorator/CreatorValidate.d.ts +1 -1
  120. package/dist/types/Framework/Decorator/JsonAdminValidate.d.ts +1 -1
  121. package/dist/types/Framework/Decorator/JsonAuthorityValidate.d.ts +2 -2
  122. package/dist/types/Framework/Decorator/JsonCreatorValidate.d.ts +1 -1
  123. package/dist/types/Framework/Decorator/SyncCall.d.ts +12 -12
  124. package/dist/types/Framework/Decorator/SyncCallServer.d.ts +14 -14
  125. package/dist/types/Framework/Logic/CacheTool.d.ts +27 -27
  126. package/dist/types/Framework/Logic/EventTool.d.ts +11 -12
  127. package/dist/types/Framework/Logic/HttpTool.d.ts +19 -19
  128. package/dist/types/Framework/Logic/Log.d.ts +18 -18
  129. package/dist/types/Framework/Logic/SyncQueueTool.d.ts +21 -21
  130. package/dist/types/Framework/Server/ProtoFilter/GoogleProtoFilter.d.ts +9 -9
  131. package/dist/types/Framework/Server/ProtoFilter/IProtoFilter.d.ts +10 -10
  132. package/dist/types/Framework/Server/ProtoFilter/JsonProtoFilter.d.ts +6 -6
  133. package/dist/types/Framework/Server/ProtoFilter/ProtoFactory.d.ts +12 -12
  134. package/dist/types/Framework/Server/RpcWebSocketServer/CgMq.d.ts +59 -59
  135. package/dist/types/Framework/Server/RpcWebSocketServer/IRpc.d.ts +33 -33
  136. package/dist/types/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.d.ts +34 -34
  137. package/dist/types/Framework/Server/RpcWebSocketServer/IRpcServerWebSocket.d.ts +23 -23
  138. package/dist/types/Framework/Server/SocketServer/IClientSocket.d.ts +16 -18
  139. package/dist/types/Framework/Server/SocketServer/IServerSocket.d.ts +27 -29
  140. package/dist/types/Framework/Server/SocketServer/ISocket.d.ts +78 -81
  141. package/dist/types/Framework/Server/SocketServer/ISocketServer.d.ts +44 -45
  142. package/dist/types/Framework/Server/SocketServer/PacketParser.d.ts +8 -10
  143. package/dist/types/Framework/Server/WebServer/Controller/BaseController.d.ts +34 -34
  144. package/dist/types/Framework/Server/WebServer/Controller/MongoBaseUserController.d.ts +28 -28
  145. package/dist/types/Framework/Server/WebServer/Controller/MysqlBaseUserController.d.ts +27 -27
  146. package/dist/types/Framework/Server/WebServer/Engine/ControllerManager.d.ts +37 -37
  147. package/dist/types/Framework/Server/WebServer/Engine/Engine.d.ts +42 -44
  148. package/dist/types/Framework/Server/WebServer/Engine/RazorJs.d.ts +21 -21
  149. package/dist/types/Framework/Server/WebServer/Engine/Request.d.ts +47 -50
  150. package/dist/types/Framework/Server/WebServer/Engine/Response.d.ts +26 -26
  151. package/dist/types/Framework/Server/WebServer/IWebServer.d.ts +22 -22
  152. package/dist/types/Framework/Server/WebSocketServer/IClientWebSocket.d.ts +17 -17
  153. package/dist/types/Framework/Server/WebSocketServer/IServerWebSocket.d.ts +37 -38
  154. package/dist/types/Framework/Server/WebSocketServer/IWebSocket.d.ts +76 -76
  155. package/dist/types/Framework/Server/WebSocketServer/IWebSocketServer.d.ts +49 -49
  156. package/dist/types/Framework/Service/MongoAccountService.d.ts +62 -62
  157. package/dist/types/Framework/Service/MongoCacheService.d.ts +19 -19
  158. package/dist/types/Framework/Service/MongoUserService.d.ts +31 -31
  159. package/dist/types/Framework/Service/MysqlAccountService.d.ts +67 -67
  160. package/dist/types/Framework/Service/MysqlUserService.d.ts +33 -33
  161. package/dist/types/Framework/Service/ini.d.ts +29 -29
  162. package/dist/types/Framework/ThirdParty/AlipayTool.d.ts +76 -108
  163. package/dist/types/Framework/ThirdParty/Alisms.d.ts +23 -13
  164. package/dist/types/Framework/ThirdParty/AppleTool.d.ts +131 -131
  165. package/dist/types/Framework/ThirdParty/CgRankTool.d.ts +107 -107
  166. package/dist/types/Framework/ThirdParty/EmailTool.d.ts +4 -4
  167. package/dist/types/Framework/ThirdParty/QQTool.d.ts +41 -41
  168. package/dist/types/Framework/ThirdParty/QiniuTool.d.ts +5 -5
  169. package/dist/types/Framework/ThirdParty/Rpc.d.ts +28 -28
  170. package/dist/types/Framework/ThirdParty/WechatTool.d.ts +30 -30
  171. package/dist/types/Framework/cgserver.d.ts +63 -63
  172. package/dist/types/Framework/global.d.ts +45 -45
  173. package/dist/types/Framework/index.d.ts +2 -2
  174. package/dist/types/Framework/index_export_.d.ts +81 -79
  175. package/dist/types/test/test.d.ts +1 -1
  176. package/package.json +8 -4
@@ -1,235 +1,271 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gAppleTool = exports.AppleTool = exports.NotificationBody = exports.NotificationType = exports.ResponseBody = void 0;
4
- const ec_key_1 = require("ec-key");
5
- const uuid_1 = require("uuid");
6
- const fs = require("fs");
7
- const Config_1 = require("../Config/Config");
8
- const Log_1 = require("../Logic/Log");
9
- const HttpTool_1 = require("../Logic/HttpTool");
10
- const IServerConfig_1 = require("../Config/IServerConfig");
11
- //developer.apple.com/documentation/appstorereceipts/responsebody
12
- class ReceiptInfo {
13
- cancellation_date = "";
14
- cancellation_date_ms = "";
15
- cancellation_date_pst = "";
16
- cancellation_date_reason = "";
17
- expires_date = "2021-03-10 14:25:54 Etc/GMT";
18
- expires_date_ms = "1615386354000";
19
- expires_date_pst = "2021-03-10 06:25:54 America/Los_Angeles";
20
- in_app_ownership_type;
21
- is_in_intro_offer_period = false;
22
- is_trial_period = false;
23
- is_upgraded = false;
24
- offer_code_ref_name = "";
25
- original_purchase_date = "2021-03-10 08:22:26 Etc/GMT";
26
- original_purchase_date_ms = "1615364546000";
27
- original_purchase_date_pst = "2021-03-10 00:22:26 America/Los_Angeles";
28
- original_transaction_id = "1000000786747716";
29
- purchase_date = "2021-03-10 14:22:54 Etc/GMT";
30
- purchase_date_ms = "1615386174000";
31
- purchase_date_pst = "2021-03-10 06:22:54 America/Los_Angeles";
32
- quantity = 1;
33
- subscription_group_identifier = "20745320";
34
- web_order_line_item_id = "1000000060695307";
35
- transaction_id = "1000000786974540";
36
- product_id = "com.eryi.eyreader.week";
37
- }
38
- class PendingRenewalInfo {
39
- auto_renew_product_id = "com.eryi.eyreader.week";
40
- auto_renew_status = 0;
41
- expiration_intent = 1;
42
- grace_period_expires_date = "";
43
- grace_period_expires_date_ms = "";
44
- grace_period_expires_date_pst = "";
45
- is_in_billing_retry_period = 0;
46
- offer_code_ref_name = "";
47
- original_transaction_id = "1000000786747716";
48
- price_consent_status = "";
49
- product_id = "com.eryi.eyreader.week";
50
- promotional_offer_id = "";
51
- }
52
- class InApp {
53
- cancellation_date = "";
54
- cancellation_date_ms = "";
55
- cancellation_date_pst = "";
56
- cancellation_reason = "";
57
- expires_date = "2021-03-10 14:25:54 Etc/GMT";
58
- expires_date_ms = "1615386354000";
59
- expires_date_pst = "2021-03-10 06:25:54 America/Los_Angeles";
60
- is_in_intro_offer_period = false;
61
- is_trial_period = false;
62
- original_purchase_date = "2021-03-10 08:22:26 Etc/GMT";
63
- original_purchase_date_ms = "1615364546000";
64
- original_purchase_date_pst = "2021-03-10 00:22:26 America/Los_Angeles";
65
- original_transaction_id = "1000000786747716";
66
- product_id = "com.eryi.eyreader.week";
67
- promotional_offer_id = "";
68
- purchase_date = "2021-03-10 14:22:54 Etc/GMT";
69
- purchase_date_ms = "1615386174000";
70
- purchase_date_pst = "2021-03-10 06:22:54 America/Los_Angeles";
71
- quantity = 1;
72
- transaction_id = "1000000786974540";
73
- web_order_line_item_id = "1000000060695307";
74
- }
75
- class Receipt {
76
- adam_id = -1;
77
- app_item_id = -1;
78
- application_version = "";
79
- bundle_id = "";
80
- download_id = -1;
81
- expiration_date = "";
82
- expiration_date_ms = "";
83
- expiration_date_pst = "";
84
- in_app = null;
85
- original_application_version = "";
86
- original_purchase_date = "";
87
- original_purchase_date_ms = "";
88
- original_purchase_date_pst = "";
89
- preorder_date = "";
90
- preorder_date_ms = "";
91
- preorder_date_pst = "";
92
- receipt_creation_date = "";
93
- receipt_creation_date_ms = "";
94
- receipt_creation_date_pst = "";
95
- receipt_type = "";
96
- request_date = "";
97
- request_date_ms = "";
98
- request_date_pst = "";
99
- version_external_identifier = -1;
100
- }
101
- class ResponseBody {
102
- environment = "Sandbox";
103
- is_retryable = false; //出错之后的重试
104
- latest_receipt = "0OkG/Sw==";
105
- latest_receipt_info = null;
106
- pending_renewal_info = null;
107
- receipt = null;
108
- status = 0;
109
- }
110
- exports.ResponseBody = ResponseBody;
111
- class NotificationType {
112
- //退款
113
- static CANCEL = "CANCEL";
114
- //变更续订方式,下次续订的时候生效,当前不变
115
- static DID_CHANGE_RENEWAL_PREF = "DID_CHANGE_RENEWAL_PREF";
116
- /*
117
- 续订状态发生变化的时候通知
118
- 检查auto_renew_status_change_date_ms获取最新的状态更新时间.
119
- 通过auto_renew_status了解当前续订状态.
120
- */
121
- static DID_CHANGE_RENEWAL_STATUS = "DID_CHANGE_RENEWAL_STATUS";
122
- //自动续订了一个之前续订失败了的续订
123
- static DID_RECOVER = "DID_RECOVER";
124
- //自动续订成功
125
- static DID_RENEW = "DID_RENEW";
126
- //客户交互更新订阅,订阅可以立刻生效
127
- static INTERACTIVE_RENEWAL = "INTERACTIVE_RENEWAL";
128
- }
129
- exports.NotificationType = NotificationType;
130
- class NotificationBody {
131
- unified_receipt = null;
132
- environment = "Sandbox";
133
- auto_renew_status = "false";
134
- auto_renew_status_change_date = "2021-03-11 03:03:14 Etc/GMT";
135
- bvrs = "1";
136
- bid = "com.eryi.eyreader";
137
- password = "5203c7781e254aac8942290a0a2467ac";
138
- auto_renew_product_id = "com.eryi.eyreader.week";
139
- notification_type = NotificationType.DID_RECOVER;
140
- }
141
- exports.NotificationBody = NotificationBody;
142
- class RequestBody {
143
- "receipt-data" = "";
144
- password = "5203c7781e254aac8942290a0a2467ac";
145
- "exclude-old-transactions" = true;
146
- }
147
- class AppleTool {
148
- _verifyUrl = "https://buy.itunes.apple.com/verifyReceipt";
149
- _sandboxVerifyUrl = "https://sandbox.itunes.apple.com/verifyReceipt";
150
- async onNotify(nb) {
151
- let ris = nb.unified_receipt?.latest_receipt_info;
152
- var latest_one = (ris?.length > 0 ? ris[0] : null);
153
- let msg = {
154
- "notification_type": nb.notification_type,
155
- "status": nb.unified_receipt.status,
156
- "environment": nb.environment,
157
- "auto_renew_status": nb.auto_renew_status,
158
- "orginal_transaction_id": latest_one?.original_transaction_id,
159
- "transaction_id": latest_one?.transaction_id,
160
- "expire_date": latest_one?.expires_date,
161
- "receipt_expire_date": nb.unified_receipt?.receipt?.expiration_date
162
- };
163
- Log_1.gLog.info(msg);
164
- Log_1.gLog.info(nb);
165
- }
166
- async onVerify(receipt, environment) {
167
- Log_1.gLog.info("begin onVerify============================" + environment);
168
- let url = this._verifyUrl;
169
- // if(environment.toLowerCase()=="sandbox")
170
- // {
171
- // url=this._sandboxVerifyUrl
172
- // }
173
- Log_1.gLog.info("url============================" + url);
174
- let reqb = new RequestBody();
175
- reqb['receipt-data'] = receipt;
176
- //先验证生产环境
177
- var resb = (await HttpTool_1.gHttpTool.post({ url, form: JSON.stringify(reqb) })).body;
178
- Log_1.gLog.info("production end onVerify_Res============================status=" + (resb ? resb.status : "null"));
179
- //状态21007表示是沙盒环境
180
- if (resb && resb.status == 21007) {
181
- url = this._sandboxVerifyUrl;
182
- resb = (await HttpTool_1.gHttpTool.post({ url, form: JSON.stringify(reqb) })).body;
183
- Log_1.gLog.info("sandbox end onVerify_Res============================status=" + (resb ? resb.status : "null"));
184
- }
185
- Log_1.gLog.info(resb);
186
- return resb;
187
- }
188
- signature(nickname, create_time, appBundleID, productIdentifier, offerIdentifier) {
189
- let keyIdentifier = "";
190
- for (var k in IServerConfig_1.gServerCfg.apple.keyIds) {
191
- keyIdentifier = k;
192
- break;
193
- }
194
- var nonce = (0, uuid_1.v4)();
195
- var payload = appBundleID + '\u2063' +
196
- keyIdentifier + '\u2063' +
197
- productIdentifier + '\u2063' +
198
- offerIdentifier + '\u2063' +
199
- nickname + '\u2063' +
200
- nonce.toLowerCase() + '\u2063' +
201
- create_time;
202
- // Get the PEM-formatted private key string associated with the Key ID.
203
- const path = IServerConfig_1.gServerCfg.apple.keyIds[keyIdentifier];
204
- const keyString = fs.readFileSync(Config_1.Config.rootDataDir + path).toString();
205
- // Create an Elliptic Curve Digital Signature Algorithm (ECDSA) object using the private key.
206
- const key = new ec_key_1.default(keyString, 'pem');
207
- // Set up the cryptographic format used to sign the key with the SHA-256 hashing algorithm.
208
- const cryptoSign = key.createSign('SHA256');
209
- // Add the payload string to sign.
210
- cryptoSign.update(payload);
211
- /*
212
- The Node.js crypto library creates a DER-formatted binary value signature,
213
- and then base-64 encodes it to create the string that you will use in StoreKit.
214
- */
215
- const signature = cryptoSign.sign('base64');
216
- /*
217
- Check that the signature passes verification by using the ec-key library.
218
- The verification process is similar to creating the signature, except it uses 'createVerify'
219
- instead of 'createSign', and after updating it with the payload, it uses `verify` to pass in
220
- the signature and encoding, instead of `sign` to get the signature.
221
-
222
- This step is not required, but it's useful to check when implementing your signature code.
223
- This helps debug issues with signing before sending transactions to Apple.
224
- If verification succeeds, the next recommended testing step is attempting a purchase
225
- in the Sandbox environment.
226
- */
227
- const verificationResult = key.createVerify('SHA256').update(payload).verify(signature, 'base64');
228
- if (verificationResult) {
229
- return { 'keyIdentifier': keyIdentifier, 'nonce': nonce, 'timestamp': create_time, 'signature': signature };
230
- }
231
- return;
232
- }
233
- }
234
- exports.AppleTool = AppleTool;
235
- exports.gAppleTool = new AppleTool();
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.gAppleTool = exports.AppleTool = exports.NotificationBody = exports.NotificationType = exports.ResponseBody = void 0;
40
+ const ec_key_1 = __importDefault(require("ec-key"));
41
+ const uuid_1 = require("uuid");
42
+ const fs = __importStar(require("fs"));
43
+ const Config_1 = require("../Config/Config");
44
+ const Log_1 = require("../Logic/Log");
45
+ const HttpTool_1 = require("../Logic/HttpTool");
46
+ const IServerConfig_1 = require("../Config/IServerConfig");
47
+ //developer.apple.com/documentation/appstorereceipts/responsebody
48
+ class ReceiptInfo {
49
+ cancellation_date = "";
50
+ cancellation_date_ms = "";
51
+ cancellation_date_pst = "";
52
+ cancellation_date_reason = "";
53
+ expires_date = "2021-03-10 14:25:54 Etc/GMT";
54
+ expires_date_ms = "1615386354000";
55
+ expires_date_pst = "2021-03-10 06:25:54 America/Los_Angeles";
56
+ in_app_ownership_type;
57
+ is_in_intro_offer_period = false;
58
+ is_trial_period = false;
59
+ is_upgraded = false;
60
+ offer_code_ref_name = "";
61
+ original_purchase_date = "2021-03-10 08:22:26 Etc/GMT";
62
+ original_purchase_date_ms = "1615364546000";
63
+ original_purchase_date_pst = "2021-03-10 00:22:26 America/Los_Angeles";
64
+ original_transaction_id = "1000000786747716";
65
+ purchase_date = "2021-03-10 14:22:54 Etc/GMT";
66
+ purchase_date_ms = "1615386174000";
67
+ purchase_date_pst = "2021-03-10 06:22:54 America/Los_Angeles";
68
+ quantity = 1;
69
+ subscription_group_identifier = "20745320";
70
+ web_order_line_item_id = "1000000060695307";
71
+ transaction_id = "1000000786974540";
72
+ product_id = "com.eryi.eyreader.week";
73
+ }
74
+ class PendingRenewalInfo {
75
+ auto_renew_product_id = "com.eryi.eyreader.week";
76
+ auto_renew_status = 0;
77
+ expiration_intent = 1;
78
+ grace_period_expires_date = "";
79
+ grace_period_expires_date_ms = "";
80
+ grace_period_expires_date_pst = "";
81
+ is_in_billing_retry_period = 0;
82
+ offer_code_ref_name = "";
83
+ original_transaction_id = "1000000786747716";
84
+ price_consent_status = "";
85
+ product_id = "com.eryi.eyreader.week";
86
+ promotional_offer_id = "";
87
+ }
88
+ class InApp {
89
+ cancellation_date = "";
90
+ cancellation_date_ms = "";
91
+ cancellation_date_pst = "";
92
+ cancellation_reason = "";
93
+ expires_date = "2021-03-10 14:25:54 Etc/GMT";
94
+ expires_date_ms = "1615386354000";
95
+ expires_date_pst = "2021-03-10 06:25:54 America/Los_Angeles";
96
+ is_in_intro_offer_period = false;
97
+ is_trial_period = false;
98
+ original_purchase_date = "2021-03-10 08:22:26 Etc/GMT";
99
+ original_purchase_date_ms = "1615364546000";
100
+ original_purchase_date_pst = "2021-03-10 00:22:26 America/Los_Angeles";
101
+ original_transaction_id = "1000000786747716";
102
+ product_id = "com.eryi.eyreader.week";
103
+ promotional_offer_id = "";
104
+ purchase_date = "2021-03-10 14:22:54 Etc/GMT";
105
+ purchase_date_ms = "1615386174000";
106
+ purchase_date_pst = "2021-03-10 06:22:54 America/Los_Angeles";
107
+ quantity = 1;
108
+ transaction_id = "1000000786974540";
109
+ web_order_line_item_id = "1000000060695307";
110
+ }
111
+ class Receipt {
112
+ adam_id = -1;
113
+ app_item_id = -1;
114
+ application_version = "";
115
+ bundle_id = "";
116
+ download_id = -1;
117
+ expiration_date = "";
118
+ expiration_date_ms = "";
119
+ expiration_date_pst = "";
120
+ in_app = null;
121
+ original_application_version = "";
122
+ original_purchase_date = "";
123
+ original_purchase_date_ms = "";
124
+ original_purchase_date_pst = "";
125
+ preorder_date = "";
126
+ preorder_date_ms = "";
127
+ preorder_date_pst = "";
128
+ receipt_creation_date = "";
129
+ receipt_creation_date_ms = "";
130
+ receipt_creation_date_pst = "";
131
+ receipt_type = "";
132
+ request_date = "";
133
+ request_date_ms = "";
134
+ request_date_pst = "";
135
+ version_external_identifier = -1;
136
+ }
137
+ class ResponseBody {
138
+ environment = "Sandbox";
139
+ is_retryable = false; //出错之后的重试
140
+ latest_receipt = "0OkG/Sw==";
141
+ latest_receipt_info = null;
142
+ pending_renewal_info = null;
143
+ receipt = null;
144
+ status = 0;
145
+ }
146
+ exports.ResponseBody = ResponseBody;
147
+ class NotificationType {
148
+ //退款
149
+ static CANCEL = "CANCEL";
150
+ //变更续订方式,下次续订的时候生效,当前不变
151
+ static DID_CHANGE_RENEWAL_PREF = "DID_CHANGE_RENEWAL_PREF";
152
+ /*
153
+ 续订状态发生变化的时候通知
154
+ 检查auto_renew_status_change_date_ms获取最新的状态更新时间.
155
+ 通过auto_renew_status了解当前续订状态.
156
+ */
157
+ static DID_CHANGE_RENEWAL_STATUS = "DID_CHANGE_RENEWAL_STATUS";
158
+ //自动续订了一个之前续订失败了的续订
159
+ static DID_RECOVER = "DID_RECOVER";
160
+ //自动续订成功
161
+ static DID_RENEW = "DID_RENEW";
162
+ //客户交互更新订阅,订阅可以立刻生效
163
+ static INTERACTIVE_RENEWAL = "INTERACTIVE_RENEWAL";
164
+ }
165
+ exports.NotificationType = NotificationType;
166
+ class NotificationBody {
167
+ unified_receipt = null;
168
+ environment = "Sandbox";
169
+ auto_renew_status = "false";
170
+ auto_renew_status_change_date = "2021-03-11 03:03:14 Etc/GMT";
171
+ bvrs = "1";
172
+ bid = "com.eryi.eyreader";
173
+ password = "5203c7781e254aac8942290a0a2467ac";
174
+ auto_renew_product_id = "com.eryi.eyreader.week";
175
+ notification_type = NotificationType.DID_RECOVER;
176
+ }
177
+ exports.NotificationBody = NotificationBody;
178
+ class RequestBody {
179
+ "receipt-data" = "";
180
+ password = "5203c7781e254aac8942290a0a2467ac";
181
+ "exclude-old-transactions" = true;
182
+ }
183
+ class AppleTool {
184
+ _verifyUrl = "https://buy.itunes.apple.com/verifyReceipt";
185
+ _sandboxVerifyUrl = "https://sandbox.itunes.apple.com/verifyReceipt";
186
+ async onNotify(nb) {
187
+ let ris = nb.unified_receipt?.latest_receipt_info;
188
+ var latest_one = (ris?.length > 0 ? ris[0] : null);
189
+ let msg = {
190
+ "notification_type": nb.notification_type,
191
+ "status": nb.unified_receipt.status,
192
+ "environment": nb.environment,
193
+ "auto_renew_status": nb.auto_renew_status,
194
+ "orginal_transaction_id": latest_one?.original_transaction_id,
195
+ "transaction_id": latest_one?.transaction_id,
196
+ "expire_date": latest_one?.expires_date,
197
+ "receipt_expire_date": nb.unified_receipt?.receipt?.expiration_date
198
+ };
199
+ Log_1.gLog.info(msg);
200
+ Log_1.gLog.info(nb);
201
+ }
202
+ async onVerify(receipt, environment) {
203
+ Log_1.gLog.info("begin onVerify============================" + environment);
204
+ let url = this._verifyUrl;
205
+ // if(environment.toLowerCase()=="sandbox")
206
+ // {
207
+ // url=this._sandboxVerifyUrl
208
+ // }
209
+ Log_1.gLog.info("url============================" + url);
210
+ let reqb = new RequestBody();
211
+ reqb['receipt-data'] = receipt;
212
+ //先验证生产环境
213
+ var resb = (await HttpTool_1.gHttpTool.post({ url, form: JSON.stringify(reqb) })).body;
214
+ Log_1.gLog.info("production end onVerify_Res============================status=" + (resb ? resb.status : "null"));
215
+ //状态21007表示是沙盒环境
216
+ if (resb && resb.status == 21007) {
217
+ url = this._sandboxVerifyUrl;
218
+ resb = (await HttpTool_1.gHttpTool.post({ url, form: JSON.stringify(reqb) })).body;
219
+ Log_1.gLog.info("sandbox end onVerify_Res============================status=" + (resb ? resb.status : "null"));
220
+ }
221
+ Log_1.gLog.info(resb);
222
+ return resb;
223
+ }
224
+ signature(nickname, create_time, appBundleID, productIdentifier, offerIdentifier) {
225
+ let keyIdentifier = "";
226
+ for (var k in IServerConfig_1.gServerCfg.apple.keyIds) {
227
+ keyIdentifier = k;
228
+ break;
229
+ }
230
+ var nonce = (0, uuid_1.v4)();
231
+ var payload = appBundleID + '\u2063' +
232
+ keyIdentifier + '\u2063' +
233
+ productIdentifier + '\u2063' +
234
+ offerIdentifier + '\u2063' +
235
+ nickname + '\u2063' +
236
+ nonce.toLowerCase() + '\u2063' +
237
+ create_time;
238
+ // Get the PEM-formatted private key string associated with the Key ID.
239
+ const path = IServerConfig_1.gServerCfg.apple.keyIds[keyIdentifier];
240
+ const keyString = fs.readFileSync(Config_1.Config.rootDataDir + path).toString();
241
+ // Create an Elliptic Curve Digital Signature Algorithm (ECDSA) object using the private key.
242
+ const key = new ec_key_1.default(keyString, 'pem');
243
+ // Set up the cryptographic format used to sign the key with the SHA-256 hashing algorithm.
244
+ const cryptoSign = key.createSign('SHA256');
245
+ // Add the payload string to sign.
246
+ cryptoSign.update(payload);
247
+ /*
248
+ The Node.js crypto library creates a DER-formatted binary value signature,
249
+ and then base-64 encodes it to create the string that you will use in StoreKit.
250
+ */
251
+ const signature = cryptoSign.sign('base64');
252
+ /*
253
+ Check that the signature passes verification by using the ec-key library.
254
+ The verification process is similar to creating the signature, except it uses 'createVerify'
255
+ instead of 'createSign', and after updating it with the payload, it uses `verify` to pass in
256
+ the signature and encoding, instead of `sign` to get the signature.
257
+
258
+ This step is not required, but it's useful to check when implementing your signature code.
259
+ This helps debug issues with signing before sending transactions to Apple.
260
+ If verification succeeds, the next recommended testing step is attempting a purchase
261
+ in the Sandbox environment.
262
+ */
263
+ const verificationResult = key.createVerify('SHA256').update(payload).verify(signature, 'base64');
264
+ if (verificationResult) {
265
+ return { 'keyIdentifier': keyIdentifier, 'nonce': nonce, 'timestamp': create_time, 'signature': signature };
266
+ }
267
+ return;
268
+ }
269
+ }
270
+ exports.AppleTool = AppleTool;
271
+ exports.gAppleTool = new AppleTool();