質問編集履歴
1
プログラム追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,4 +12,204 @@
|
|
12
12
|
|
13
13
|
検索しても原因や対策がわかりそうな情報がみつからず困っています。
|
14
14
|
似たような症状に遭遇した方や原因に見当がつく方がいましたら解決に向けて情報を頂けると助かります。
|
15
|
-
よろしくお願い致します。
|
15
|
+
よろしくお願い致します。
|
16
|
+
|
17
|
+
---以下6/27追記(実際に使っている物から不要箇所削除しID類情報を変更するなど加工して掲載)---
|
18
|
+
|
19
|
+
```c#
|
20
|
+
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_TVOS
|
21
|
+
//#define RECEIPT_VALIDATION
|
22
|
+
#endif
|
23
|
+
|
24
|
+
using System;
|
25
|
+
using System.Collections.Generic;
|
26
|
+
using UnityEngine;
|
27
|
+
using UnityEngine.Purchasing;
|
28
|
+
#if RECEIPT_VALIDATION
|
29
|
+
using UnityEngine.Purchasing.Security;
|
30
|
+
#endif
|
31
|
+
|
32
|
+
public class Unity5Purchase : MonoBehaviour, IStoreListener {
|
33
|
+
private static IStoreController m_StoreController;
|
34
|
+
private static IExtensionProvider m_StoreExtensionProvider;
|
35
|
+
#if RECEIPT_VALIDATION
|
36
|
+
private CrossPlatformValidator validator;
|
37
|
+
#endif
|
38
|
+
|
39
|
+
// GooglePlayライセンスコード.
|
40
|
+
const string API_KEY = "(ないしょ)";
|
41
|
+
|
42
|
+
void Start() {
|
43
|
+
if (m_StoreController == null) {
|
44
|
+
InitializePurchasing();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
public void InitializePurchasing() {
|
49
|
+
if (IsInitialized()) {
|
50
|
+
return;// 初期化済み.
|
51
|
+
}
|
52
|
+
var module = StandardPurchasingModule.Instance();
|
53
|
+
var builder = ConfigurationBuilder.Instance(module);
|
54
|
+
builder.Configure<IGooglePlayConfiguration>().SetPublicKey(API_KEY);// GooglePlayのライセンスキー登録.
|
55
|
+
// (以下のID等は実際に使っている物とは違います今回のための仮記載情報です)
|
56
|
+
builder.AddProduct("PRODUCT_ID1", ProductType.Consumable, new IDs {
|
57
|
+
{ "test01", GooglePlay.Name },
|
58
|
+
{ "TEST01", AppleApPStore.Name },
|
59
|
+
{ "Test01", MacAppStore.Name },
|
60
|
+
});
|
61
|
+
builder.AddProduct("PRODUCT_ID2", ProductType.Consumable, new IDs {
|
62
|
+
{ "test02", GooglePlay.Name },
|
63
|
+
{ "TEST02", AppleApPStore.Name },
|
64
|
+
{ "Test02", MacAppStore.Name },
|
65
|
+
});
|
66
|
+
#if RECEIPT_VALIDATION
|
67
|
+
validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier);
|
68
|
+
#endif
|
69
|
+
UnityPurchasing.Initialize(this, builder);
|
70
|
+
}
|
71
|
+
|
72
|
+
private bool IsInitialized() {
|
73
|
+
return m_StoreController != null && m_StoreExtensionProvider != null;
|
74
|
+
}
|
75
|
+
|
76
|
+
// 購入ボタン押下時にここを呼び出す.
|
77
|
+
void BuyProductID(string productId) {
|
78
|
+
if (IsInitialized()) {
|
79
|
+
Product product = m_StoreController.products.WithID(productId);
|
80
|
+
if (product != null && product.availableToPurchase) {
|
81
|
+
m_StoreController.InitiatePurchase(product);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
public void RestorePurchases() {
|
87
|
+
}
|
88
|
+
|
89
|
+
//
|
90
|
+
// --- IStoreListener
|
91
|
+
//
|
92
|
+
|
93
|
+
// 初期化成功時.
|
94
|
+
public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
|
95
|
+
m_StoreController = controller;
|
96
|
+
m_StoreExtensionProvider = extensions;
|
97
|
+
}
|
98
|
+
|
99
|
+
// 初期化失敗.
|
100
|
+
public void OnInitializeFailed(InitializationFailureReason error) {
|
101
|
+
}
|
102
|
+
|
103
|
+
[Serializable]
|
104
|
+
class unityReceipt {
|
105
|
+
public string Store;
|
106
|
+
public string TransactionID;
|
107
|
+
public string Payload;
|
108
|
+
public unityReceipt() {
|
109
|
+
this.Store = null;
|
110
|
+
this.TransactionID = null;
|
111
|
+
this.Payload = null;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
[Serializable]
|
116
|
+
class googlePlayPayload {
|
117
|
+
public string json;
|
118
|
+
public string signature;
|
119
|
+
public googlePlayPayload() {
|
120
|
+
this.json = null;
|
121
|
+
this.signature = null;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
[Serializable]
|
125
|
+
class googlePayloadJson {
|
126
|
+
public string orderId;
|
127
|
+
public string packageName;
|
128
|
+
public string productId;
|
129
|
+
public uint purchaseTime;
|
130
|
+
public uint purchaseState;
|
131
|
+
public string purchaseToken;
|
132
|
+
public googlePayloadJson() {
|
133
|
+
this.orderId = null;
|
134
|
+
this.packageName = null;
|
135
|
+
this.productId = null;
|
136
|
+
this.purchaseTime = 0;
|
137
|
+
this.purchaseState = 0;
|
138
|
+
this.purchaseToken = null;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
private string getReceiptPayload(string strReceipt) {
|
143
|
+
unityReceipt u5r = JsonUtility.FromJson<unityReceipt>(strReceipt);
|
144
|
+
if (u5r != null) {
|
145
|
+
string receipt = null;
|
146
|
+
googlePlayPayload gpp = JsonUtility.FromJson<googlePlayPayload>(u5r.Payload);
|
147
|
+
if (gpp != null) {
|
148
|
+
receipt = gpp.json;
|
149
|
+
if (!string.IsNullOrEmpty(receipt)) {
|
150
|
+
googlePayloadJson googleJson = JsonUtility.FromJson<googlePayloadJson>(receipt);
|
151
|
+
if (googleJson != null) {
|
152
|
+
receipt = googleJson.orderId;// ←何故かSandboxでしか存在しない.
|
153
|
+
} else {
|
154
|
+
receipt = null;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
#if RECEIPT_VALIDATION
|
159
|
+
if (Application.platform == RuntimePlatform.Android) {
|
160
|
+
try {
|
161
|
+
var result = validator.Validate(strReceipt);// ←この中でクラッシュ.
|
162
|
+
foreach (IPurchaseReceipt productReceipt in result) {
|
163
|
+
GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
|
164
|
+
if (null != google) {
|
165
|
+
|
166
|
+
}
|
167
|
+
}
|
168
|
+
} catch (IAPSecurityException) {
|
169
|
+
receipt = null;// 不正なレシートだったので不成立とする.
|
170
|
+
}
|
171
|
+
}
|
172
|
+
#endif
|
173
|
+
return receipt;// OK
|
174
|
+
}
|
175
|
+
return null;
|
176
|
+
}
|
177
|
+
// 購入実行(成功).
|
178
|
+
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
|
179
|
+
bool given = false;
|
180
|
+
if (String.Equals(args.purchasedProduct.definition.id, "PRODUCT_ID1", StringComparison.Ordinal)) {
|
181
|
+
string receipt = getReceiptPayload(args.purchasedProduct.receipt, "test01");
|
182
|
+
if (string.IsNullOrEmpty(receipt)) {
|
183
|
+
// 不正?想定外?
|
184
|
+
} else {
|
185
|
+
// (ここで付与)
|
186
|
+
given = true;
|
187
|
+
}
|
188
|
+
} else if (String.Equals(args.purchasedProduct.definition.id, "PRODUCT_ID2", StringComparison.Ordinal)) {
|
189
|
+
string receipt = getReceiptPayload(args.purchasedProduct.receipt, "test02");
|
190
|
+
if (string.IsNullOrEmpty(receipt)) {
|
191
|
+
// 不正?想定外?
|
192
|
+
} else {
|
193
|
+
// (ここで付与)
|
194
|
+
given = true;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
if (!given) {
|
198
|
+
// (付与失敗)
|
199
|
+
}
|
200
|
+
return PurchaseProcessingResult.Complete;
|
201
|
+
}
|
202
|
+
|
203
|
+
// 購入失敗.
|
204
|
+
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) {
|
205
|
+
// (付与失敗)
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
```
|
210
|
+
|
211
|
+
あと、6/20までに何度か購入テストしていた時のレシートメールは日本語の件名で
|
212
|
+
「テスト:Google Play のご注文明細(ご注文:2016/06/??) - Goole Play ご購入ありがとうご(以下略)」
|
213
|
+
のようにきていましたが6/24以降に来ているレシートメールは全て英語の件名で
|
214
|
+
「Test: Your Google Play Order Receipt from Jun ??,2016 - Google Play Thank you. You've made a purchase (以下略)」
|
215
|
+
のように変わっていました。(メールの内容(本文)は日本語のレシートですが件名だけ英語に変わった状態)
|