Commit e9a2f24b3550d7f0ce3535bc43bb0e3bec1f7763
1 parent
bfa81dd823
Exists in
master
修改支付方法说明
Showing 1 changed file with 4 additions and 4 deletions Inline Diff
doc/AndroidDocument.md
1 | # Gump Android SDK使用文档 | 1 | # Gump Android SDK使用文档 |
2 | 2 | ||
3 | 3 | ||
4 | 接入手册 | 4 | 接入手册 |
5 | V 3.2.0 | 5 | V 3.2.0 |
6 | 2015年07月29日 | 6 | 2015年07月29日 |
7 | 7 | ||
8 | 快速入口: | 8 | 快速入口: |
9 | [支付部分服务端回调文档](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/ServerDocument.md) | 9 | [支付部分服务端回调文档](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/ServerDocument.md) |
10 | 10 | ||
11 | ## 目录 | 11 | ## 目录 |
12 | 12 | ||
13 | * [第一章 接入指南](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#) | 13 | * [第一章 接入指南](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#) |
14 | - [1. 导入资源工程](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1) | 14 | - [1. 导入资源工程](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1) |
15 | - [2. 添加资源工程](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#2) | 15 | - [2. 添加资源工程](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#2) |
16 | - [3. 代码实现](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#3) | 16 | - [3. 代码实现](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#3) |
17 | > [1.修改AndroidManifest.xml文件](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1-androidmanifest-xml) | 17 | > [1.修改AndroidManifest.xml文件](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1-androidmanifest-xml) |
18 | > [2.向Gump平台索要游戏ID(GID),完成代码接入](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#2-gump-id-gid) | 18 | > [2.向Gump平台索要游戏ID(GID),完成代码接入](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#2-gump-id-gid) |
19 | * [第二章 常见问题](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#) | 19 | * [第二章 常见问题](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#) |
20 | - [问题1: 如何避免混淆对SDK的影响?](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1-sdk) | 20 | - [问题1: 如何避免混淆对SDK的影响?](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1-sdk) |
21 | - [问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错?](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/AndroidDocument.md#2-ok) | 21 | - [问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错?](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/AndroidDocument.md#2-ok) |
22 | 22 | ||
23 | 23 | ||
24 | 24 | ||
25 | 25 | ||
26 | ## 第一章 接入指南 | 26 | ## 第一章 接入指南 |
27 | 配置环境 | 27 | 配置环境 |
28 | 28 | ||
29 | 本接口API 适用于Android2.2以上各版本Android平台。 | 29 | 本接口API 适用于Android2.2以上各版本Android平台。 |
30 | ### 1. 导入资源工程 | 30 | ### 1. 导入资源工程 |
31 | 1.将GameSDK资源工程拷贝到工作空间,在eclipse中的导航栏右键弹出如图1画面,选择Import导入资源工程,如图1. | 31 | 1.将GameSDK资源工程拷贝到工作空间,在eclipse中的导航栏右键弹出如图1画面,选择Import导入资源工程,如图1. |
32 | 注意:本sdk需要使用Facebook sdk4.4.1实现fb登录,请自行导入Facebook SDK | 32 | 注意:本sdk需要使用Facebook sdk4.4.1实现fb登录,请自行导入Facebook SDK |
33 | 33 | ||
34 |  | 34 |  |
35 | 图1 | 35 | 图1 |
36 | 36 | ||
37 | 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。 | 37 | 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。 |
38 |  | 38 |  |
39 | 图 2 | 39 | 图 2 |
40 | ### 2. 添加资源工程 | 40 | ### 2. 添加资源工程 |
41 | 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 | 41 | 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 |
42 |  | 42 |  |
43 | 图 3 | 43 | 图 3 |
44 | 44 | ||
45 | 45 | ||
46 | 注意:如果ADT版本低于14,ADT不支持jar包自动引入,请手动拷贝libs到您的工作 | 46 | 注意:如果ADT版本低于14,ADT不支持jar包自动引入,请手动拷贝libs到您的工作 |
47 | 空间。 | 47 | 空间。 |
48 | 48 | ||
49 | Eclipse查看ADT版本号的方法: | 49 | Eclipse查看ADT版本号的方法: |
50 | Help==>About Eclips点击Android对应的图标就可以查看版本了. | 50 | Help==>About Eclips点击Android对应的图标就可以查看版本了. |
51 | 如图,红色框部分就是ADT版本号。 | 51 | 如图,红色框部分就是ADT版本号。 |
52 | 52 | ||
53 |  | 53 |  |
54 | 54 | ||
55 | 55 | ||
56 | ### 3. 代码实现 | 56 | ### 3. 代码实现 |
57 | #### 1、 修改AndroidManifest.xml文件 | 57 | #### 1、 修改AndroidManifest.xml文件 |
58 | 首先添加必要的权限,如下所示: | 58 | 首先添加必要的权限,如下所示: |
59 | 59 | ||
60 | <uses-permission android:name="android.permission.INTERNET" /> | 60 | <uses-permission android:name="android.permission.INTERNET" /> |
61 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | 61 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
62 | <uses-permission android:name="android.permission.BLUETOOTH" /> | 62 | <uses-permission android:name="android.permission.BLUETOOTH" /> |
63 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | 63 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
64 | <uses-permission android:name="android.permission.WRITE_SETTINGS"/> | 64 | <uses-permission android:name="android.permission.WRITE_SETTINGS"/> |
65 | <uses-permission android:name="android.permission.GET_ACCOUNTS"/> | 65 | <uses-permission android:name="android.permission.GET_ACCOUNTS"/> |
66 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 66 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
67 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | 67 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
68 | <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | 68 | <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> |
69 | <uses-permission android:name="android.permission.SEND_SMS"/> | 69 | <uses-permission android:name="android.permission.SEND_SMS"/> |
70 | 70 | ||
71 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | 71 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> |
72 | <uses-permission android:name="com.android.vending.BILLING" /> | 72 | <uses-permission android:name="com.android.vending.BILLING" /> |
73 | 73 | ||
74 | 其次注册相应的Activity,具体如下: | 74 | 其次注册相应的Activity,具体如下: |
75 | 75 | ||
76 | <activity | 76 | <activity |
77 | android:name="com.gumptech.sdk.ContainerActivity" | 77 | android:name="com.gumptech.sdk.ContainerActivity" |
78 | android:theme="@style/container_dialog" | 78 | android:theme="@style/container_dialog" |
79 | android:configChanges="orientation|screenLayout" > | 79 | android:configChanges="orientation|screenLayout" > |
80 | </activity> | 80 | </activity> |
81 | <activity | 81 | <activity |
82 | android:name="com.facebook.LoginActivity" | 82 | android:name="com.facebook.LoginActivity" |
83 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 83 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > |
84 | </activity> | 84 | </activity> |
85 | <activity | 85 | <activity |
86 | android:name="com.gumptech.sdk.PaymentActivity" | 86 | android:name="com.gumptech.sdk.PaymentActivity" |
87 | android:configChanges="orientation|screenLayout" | 87 | android:configChanges="orientation|screenLayout" |
88 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 88 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > |
89 | </activity> | 89 | </activity> |
90 | <activity | 90 | <activity |
91 | android:name="com.gumptech.sdk.ExchangeWindow" | 91 | android:name="com.gumptech.sdk.ExchangeWindow" |
92 | android:configChanges="orientation|screenLayout" | 92 | android:configChanges="orientation|screenLayout" |
93 | android:theme="@style/ex_win" > | 93 | android:theme="@style/ex_win" > |
94 | </activity> | 94 | </activity> |
95 | <service android:name="com.gumptech.sdk.PushService" > | 95 | <service android:name="com.gumptech.sdk.PushService" > |
96 | </service> | 96 | </service> |
97 | <activity | 97 | <activity |
98 | android:name="com.facebook.FacebookActivity" | 98 | android:name="com.facebook.FacebookActivity" |
99 | android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" | 99 | android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" |
100 | android:label="@string/app_name" | 100 | android:label="@string/app_name" |
101 | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | 101 | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> |
102 | 102 | ||
103 | 103 | ||
104 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 | 104 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 |
105 | 正式开始接入逻辑代码前,先介绍下一些附加配置,以方便代码接入 | 105 | 正式开始接入逻辑代码前,先介绍下一些附加配置,以方便代码接入 |
106 | *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo | 106 | *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo |
107 | 107 | ||
108 | GumpSDK.setShowLogo(boolean); | 108 | GumpSDK.setShowLogo(boolean); |
109 | *横竖屏控制,默认为横屏,参数为false即为竖屏 | 109 | *横竖屏控制,默认为横屏,参数为false即为竖屏 |
110 | 110 | ||
111 | GumpSDK.setScreenLandscape(true); | 111 | GumpSDK.setScreenLandscape(true); |
112 | *debug模式设置 | 112 | *debug模式设置 |
113 | 113 | ||
114 | GumpSDK.setDebugState(true); | 114 | GumpSDK.setDebugState(true); |
115 | 1.调用GumpSDK前需要执行初始化。 | 115 | 1.调用GumpSDK前需要执行初始化。 |
116 | 116 | ||
117 | 若不需要分渠道 | 117 | 若不需要分渠道 |
118 | 118 | ||
119 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | 119 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); |
120 | 如果需要定义渠道,必须使用如下方法 | 120 | 如果需要定义渠道,必须使用如下方法 |
121 | 121 | ||
122 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | 122 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); |
123 | 123 | ||
124 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | 124 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 |
125 | 125 | ||
126 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 126 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 |
127 | 127 | ||
128 | GumpSDK.start(Activity); | 128 | GumpSDK.start(Activity); |
129 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 129 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: |
130 | 130 | ||
131 | GumpSDK.setUserStateListener(new LoginStateListener() { | 131 | GumpSDK.setUserStateListener(new LoginStateListener() { |
132 | @Override | 132 | @Override |
133 | public void onLoginSuccess(GumpUser gumpUser) { | 133 | public void onLoginSuccess(GumpUser gumpUser) { |
134 | //登录成功,用户信息包含在GumpUser对象里 | 134 | //登录成功,用户信息包含在GumpUser对象里 |
135 | } | 135 | } |
136 | 136 | ||
137 | @Override | 137 | @Override |
138 | public void onLoginFailed(int code, String msg) { | 138 | public void onLoginFailed(int code, String msg) { |
139 | //登录出错,根据错误码和信息判断错误类型 | 139 | //登录出错,根据错误码和信息判断错误类型 |
140 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 140 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); |
141 | } | 141 | } |
142 | 142 | ||
143 | @Override | 143 | @Override |
144 | public void onLoginCanceled() { | 144 | public void onLoginCanceled() { |
145 | //用户取消登录 | 145 | //用户取消登录 |
146 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 146 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
147 | } | 147 | } |
148 | 148 | ||
149 | @Override | 149 | @Override |
150 | public void onLogout() { | 150 | public void onLogout() { |
151 | //用户登出 | 151 | //用户登出 |
152 | 152 | ||
153 | } | 153 | } |
154 | }); | 154 | }); |
155 | 155 | ||
156 | 如上成功登录后收到的GumpUser对象包含以下信息 | 156 | 如上成功登录后收到的GumpUser对象包含以下信息 |
157 | 157 | ||
158 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 158 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! |
159 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 159 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 |
160 | gumpUser.getSessionKey();//登录的sesionKey | 160 | gumpUser.getSessionKey();//登录的sesionKey |
161 | 161 | ||
162 | 162 | ||
163 | 3.支付功能 | 163 | 3.支付功能 |
164 | 1)使用gump通行证登录,其中serverId为必传参数 | 164 | 1)使用gump通行证登录,其中除nick外所有参数为必传参数 |
165 | 165 | ||
166 | Bundle payInfo = new Bundle(); | 166 | Bundle payInfo = new Bundle(); |
167 | payInfo.putString("nick", "thi"); | 167 | payInfo.putString("nick", "thi"); |
168 | payInfo.putString("product", "元宝"); | 168 | payInfo.putString("product", "元宝"); |
169 | payInfo.putFloat("amount", 40.0f); | 169 | payInfo.putFloat("amount", 40.0f); |
170 | payInfo.putString("extraInfo", "This is demo!"); | 170 | payInfo.putString("extraInfo", "This is demo!"); |
171 | payInfo.putString("serverId", "B4003"); | 171 | payInfo.putString("serverId", "B4003"); |
172 | payInfo.putString("roleId", "10010"); | 172 | payInfo.putString("roleId", "10010"); |
173 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 173 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); |
174 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除serverId外可以设置值为空,但是字段必须全部包含 | 174 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除nick外所有字段必须全部包含 |
175 | 2)未使用gump通行证登录,需要传入用户id,serverId为必传参数 | 175 | 2)未使用gump通行证登录,需要传入用户id |
176 | 176 | ||
177 | Bundle payInfo = new Bundle(); | 177 | Bundle payInfo = new Bundle(); |
178 | payInfo.putString("nick", "thi"); | 178 | payInfo.putString("nick", "thi"); |
179 | payInfo.putString("product", "元宝"); | 179 | payInfo.putString("product", "元宝"); |
180 | payInfo.putFloat("amount", 40.0f); | 180 | payInfo.putFloat("amount", 40.0f); |
181 | payInfo.putString("extraInfo", "This is demo!"); | 181 | payInfo.putString("extraInfo", "This is demo!"); |
182 | payInfo.putString("serverId", "B4003"); | 182 | payInfo.putString("serverId", "B4003"); |
183 | payInfo.putString("roleId", "10010"); | 183 | payInfo.putString("roleId", "10010"); |
184 | GumpSDK.pay(MainActivity.this, payInfo,"1021",PurchaseCallback); | 184 | GumpSDK.pay(MainActivity.this, payInfo,userId,PurchaseCallback); |
185 | 185 | ||
186 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 186 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 |
187 | 187 | ||
188 | @Override | 188 | @Override |
189 | public void onPurchaseCompleted(PurchaseResult result) { | 189 | public void onPurchaseCompleted(PurchaseResult result) { |
190 | Log.i(TAG,"purchase completed"); | 190 | Log.i(TAG,"purchase completed"); |
191 | } | 191 | } |
192 | 192 | ||
193 | @Override | 193 | @Override |
194 | public void onPurchaseError(int code, String msg) { | 194 | public void onPurchaseError(int code, String msg) { |
195 | Log.i(TAG,"purchase error"); | 195 | Log.i(TAG,"purchase error"); |
196 | } | 196 | } |
197 | 197 | ||
198 | @Override | 198 | @Override |
199 | public void onPurchaseCanceled() { | 199 | public void onPurchaseCanceled() { |
200 | Log.i(TAG,"purchase canceled"); | 200 | Log.i(TAG,"purchase canceled"); |
201 | } | 201 | } |
202 | 202 | ||
203 | 5.注销登录 | 203 | 5.注销登录 |
204 | 204 | ||
205 | GumpSDK.logout(Activity); | 205 | GumpSDK.logout(Activity); |
206 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序! | 206 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序! |
207 | ## 第二章 常见问题 | 207 | ## 第二章 常见问题 |
208 | ### 问题1: 如何避免混淆对SDK的影响? | 208 | ### 问题1: 如何避免混淆对SDK的影响? |
209 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 209 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
210 | 类,导致SDK无法正常工作,解决方法如下: | 210 | 类,导致SDK无法正常工作,解决方法如下: |
211 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 211 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
212 | 212 | ||
213 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 213 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable |
214 | -keep public class * extends android.app.Service | 214 | -keep public class * extends android.app.Service |
215 | -keep public class com.google.vending.licensing.ILicensingService | 215 | -keep public class com.google.vending.licensing.ILicensingService |
216 | -keep public class com.android.vending.licensing.ILicensingService | 216 | -keep public class com.android.vending.licensing.ILicensingService |
217 | -keep class com.gumptech.sdk.view.* {*;} | 217 | -keep class com.gumptech.sdk.view.* {*;} |
218 | -keep class com.gumptech.sdk.web.* {*;} | 218 | -keep class com.gumptech.sdk.web.* {*;} |
219 | 219 | ||
220 | 220 | ||
221 | 使得混淆的时候不会影响SDK的命名空间。 | 221 | 使得混淆的时候不会影响SDK的命名空间。 |