質問編集履歴
1
プログラム追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,403 @@
|
|
27
27
|
似たような症状に遭遇した方や原因に見当がつく方がいましたら解決に向けて情報を頂けると助かります。
|
28
28
|
|
29
29
|
よろしくお願い致します。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
---以下6/27追記(実際に使っている物から不要箇所削除しID類情報を変更するなど加工して掲載)---
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```c#
|
38
|
+
|
39
|
+
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_TVOS
|
40
|
+
|
41
|
+
//#define RECEIPT_VALIDATION
|
42
|
+
|
43
|
+
#endif
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
using System;
|
48
|
+
|
49
|
+
using System.Collections.Generic;
|
50
|
+
|
51
|
+
using UnityEngine;
|
52
|
+
|
53
|
+
using UnityEngine.Purchasing;
|
54
|
+
|
55
|
+
#if RECEIPT_VALIDATION
|
56
|
+
|
57
|
+
using UnityEngine.Purchasing.Security;
|
58
|
+
|
59
|
+
#endif
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
public class Unity5Purchase : MonoBehaviour, IStoreListener {
|
64
|
+
|
65
|
+
private static IStoreController m_StoreController;
|
66
|
+
|
67
|
+
private static IExtensionProvider m_StoreExtensionProvider;
|
68
|
+
|
69
|
+
#if RECEIPT_VALIDATION
|
70
|
+
|
71
|
+
private CrossPlatformValidator validator;
|
72
|
+
|
73
|
+
#endif
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
// GooglePlayライセンスコード.
|
78
|
+
|
79
|
+
const string API_KEY = "(ないしょ)";
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
void Start() {
|
84
|
+
|
85
|
+
if (m_StoreController == null) {
|
86
|
+
|
87
|
+
InitializePurchasing();
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public void InitializePurchasing() {
|
96
|
+
|
97
|
+
if (IsInitialized()) {
|
98
|
+
|
99
|
+
return;// 初期化済み.
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
var module = StandardPurchasingModule.Instance();
|
104
|
+
|
105
|
+
var builder = ConfigurationBuilder.Instance(module);
|
106
|
+
|
107
|
+
builder.Configure<IGooglePlayConfiguration>().SetPublicKey(API_KEY);// GooglePlayのライセンスキー登録.
|
108
|
+
|
109
|
+
// (以下のID等は実際に使っている物とは違います今回のための仮記載情報です)
|
110
|
+
|
111
|
+
builder.AddProduct("PRODUCT_ID1", ProductType.Consumable, new IDs {
|
112
|
+
|
113
|
+
{ "test01", GooglePlay.Name },
|
114
|
+
|
115
|
+
{ "TEST01", AppleApPStore.Name },
|
116
|
+
|
117
|
+
{ "Test01", MacAppStore.Name },
|
118
|
+
|
119
|
+
});
|
120
|
+
|
121
|
+
builder.AddProduct("PRODUCT_ID2", ProductType.Consumable, new IDs {
|
122
|
+
|
123
|
+
{ "test02", GooglePlay.Name },
|
124
|
+
|
125
|
+
{ "TEST02", AppleApPStore.Name },
|
126
|
+
|
127
|
+
{ "Test02", MacAppStore.Name },
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
#if RECEIPT_VALIDATION
|
132
|
+
|
133
|
+
validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier);
|
134
|
+
|
135
|
+
#endif
|
136
|
+
|
137
|
+
UnityPurchasing.Initialize(this, builder);
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
private bool IsInitialized() {
|
144
|
+
|
145
|
+
return m_StoreController != null && m_StoreExtensionProvider != null;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
// 購入ボタン押下時にここを呼び出す.
|
152
|
+
|
153
|
+
void BuyProductID(string productId) {
|
154
|
+
|
155
|
+
if (IsInitialized()) {
|
156
|
+
|
157
|
+
Product product = m_StoreController.products.WithID(productId);
|
158
|
+
|
159
|
+
if (product != null && product.availableToPurchase) {
|
160
|
+
|
161
|
+
m_StoreController.InitiatePurchase(product);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
public void RestorePurchases() {
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
//
|
178
|
+
|
179
|
+
// --- IStoreListener
|
180
|
+
|
181
|
+
//
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
// 初期化成功時.
|
186
|
+
|
187
|
+
public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
|
188
|
+
|
189
|
+
m_StoreController = controller;
|
190
|
+
|
191
|
+
m_StoreExtensionProvider = extensions;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
// 初期化失敗.
|
198
|
+
|
199
|
+
public void OnInitializeFailed(InitializationFailureReason error) {
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
[Serializable]
|
206
|
+
|
207
|
+
class unityReceipt {
|
208
|
+
|
209
|
+
public string Store;
|
210
|
+
|
211
|
+
public string TransactionID;
|
212
|
+
|
213
|
+
public string Payload;
|
214
|
+
|
215
|
+
public unityReceipt() {
|
216
|
+
|
217
|
+
this.Store = null;
|
218
|
+
|
219
|
+
this.TransactionID = null;
|
220
|
+
|
221
|
+
this.Payload = null;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
[Serializable]
|
230
|
+
|
231
|
+
class googlePlayPayload {
|
232
|
+
|
233
|
+
public string json;
|
234
|
+
|
235
|
+
public string signature;
|
236
|
+
|
237
|
+
public googlePlayPayload() {
|
238
|
+
|
239
|
+
this.json = null;
|
240
|
+
|
241
|
+
this.signature = null;
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
[Serializable]
|
248
|
+
|
249
|
+
class googlePayloadJson {
|
250
|
+
|
251
|
+
public string orderId;
|
252
|
+
|
253
|
+
public string packageName;
|
254
|
+
|
255
|
+
public string productId;
|
256
|
+
|
257
|
+
public uint purchaseTime;
|
258
|
+
|
259
|
+
public uint purchaseState;
|
260
|
+
|
261
|
+
public string purchaseToken;
|
262
|
+
|
263
|
+
public googlePayloadJson() {
|
264
|
+
|
265
|
+
this.orderId = null;
|
266
|
+
|
267
|
+
this.packageName = null;
|
268
|
+
|
269
|
+
this.productId = null;
|
270
|
+
|
271
|
+
this.purchaseTime = 0;
|
272
|
+
|
273
|
+
this.purchaseState = 0;
|
274
|
+
|
275
|
+
this.purchaseToken = null;
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
private string getReceiptPayload(string strReceipt) {
|
284
|
+
|
285
|
+
unityReceipt u5r = JsonUtility.FromJson<unityReceipt>(strReceipt);
|
286
|
+
|
287
|
+
if (u5r != null) {
|
288
|
+
|
289
|
+
string receipt = null;
|
290
|
+
|
291
|
+
googlePlayPayload gpp = JsonUtility.FromJson<googlePlayPayload>(u5r.Payload);
|
292
|
+
|
293
|
+
if (gpp != null) {
|
294
|
+
|
295
|
+
receipt = gpp.json;
|
296
|
+
|
297
|
+
if (!string.IsNullOrEmpty(receipt)) {
|
298
|
+
|
299
|
+
googlePayloadJson googleJson = JsonUtility.FromJson<googlePayloadJson>(receipt);
|
300
|
+
|
301
|
+
if (googleJson != null) {
|
302
|
+
|
303
|
+
receipt = googleJson.orderId;// ←何故かSandboxでしか存在しない.
|
304
|
+
|
305
|
+
} else {
|
306
|
+
|
307
|
+
receipt = null;
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
#if RECEIPT_VALIDATION
|
316
|
+
|
317
|
+
if (Application.platform == RuntimePlatform.Android) {
|
318
|
+
|
319
|
+
try {
|
320
|
+
|
321
|
+
var result = validator.Validate(strReceipt);// ←この中でクラッシュ.
|
322
|
+
|
323
|
+
foreach (IPurchaseReceipt productReceipt in result) {
|
324
|
+
|
325
|
+
GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
|
326
|
+
|
327
|
+
if (null != google) {
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
} catch (IAPSecurityException) {
|
336
|
+
|
337
|
+
receipt = null;// 不正なレシートだったので不成立とする.
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
#endif
|
344
|
+
|
345
|
+
return receipt;// OK
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
return null;
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
// 購入実行(成功).
|
354
|
+
|
355
|
+
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
|
356
|
+
|
357
|
+
bool given = false;
|
358
|
+
|
359
|
+
if (String.Equals(args.purchasedProduct.definition.id, "PRODUCT_ID1", StringComparison.Ordinal)) {
|
360
|
+
|
361
|
+
string receipt = getReceiptPayload(args.purchasedProduct.receipt, "test01");
|
362
|
+
|
363
|
+
if (string.IsNullOrEmpty(receipt)) {
|
364
|
+
|
365
|
+
// 不正?想定外?
|
366
|
+
|
367
|
+
} else {
|
368
|
+
|
369
|
+
// (ここで付与)
|
370
|
+
|
371
|
+
given = true;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
} else if (String.Equals(args.purchasedProduct.definition.id, "PRODUCT_ID2", StringComparison.Ordinal)) {
|
376
|
+
|
377
|
+
string receipt = getReceiptPayload(args.purchasedProduct.receipt, "test02");
|
378
|
+
|
379
|
+
if (string.IsNullOrEmpty(receipt)) {
|
380
|
+
|
381
|
+
// 不正?想定外?
|
382
|
+
|
383
|
+
} else {
|
384
|
+
|
385
|
+
// (ここで付与)
|
386
|
+
|
387
|
+
given = true;
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
if (!given) {
|
394
|
+
|
395
|
+
// (付与失敗)
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
return PurchaseProcessingResult.Complete;
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
// 購入失敗.
|
406
|
+
|
407
|
+
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) {
|
408
|
+
|
409
|
+
// (付与失敗)
|
410
|
+
|
411
|
+
}
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
```
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
あと、6/20までに何度か購入テストしていた時のレシートメールは日本語の件名で
|
422
|
+
|
423
|
+
「テスト:Google Play のご注文明細(ご注文:2016/06/??) - Goole Play ご購入ありがとうご(以下略)」
|
424
|
+
|
425
|
+
のようにきていましたが6/24以降に来ているレシートメールは全て英語の件名で
|
426
|
+
|
427
|
+
「Test: Your Google Play Order Receipt from Jun ??,2016 - Google Play Thank you. You've made a purchase (以下略)」
|
428
|
+
|
429
|
+
のように変わっていました。(メールの内容(本文)は日本語のレシートですが件名だけ英語に変わった状態)
|