牛骨文教育服务平台(让学习变的简单)
博文笔记

cocos2dx工程中接入支付宝sdk

创建时间:2016-04-26 投稿人: 浏览次数:2605
[摘要]本文是对cocos2dx工程中接入支付宝sdk的讲解,对学习Android编程技术有所帮助,与大家分享。

1. 首先去支付宝官网下载开发者文档

2. 然后按着开发者文档将支付宝的sdk导入到你的工程中,并关联到工程中,步骤入下图:

(1)将从支付宝官方网站获得的支付宝的sdk的jar包拷贝到工程中的libs目录下,如图

(2)右键工程选择Properties,弹出如下窗口,首先选择1,其次选中2,最后点击3将拷到工程中的三个支付宝的jar包一一关联到工程中

3. 最后修改工程的AndroidManifest.xml文件,添加新的权限和支付宝的Activity,代码如下:

新权限:

1 2 3 4 5 6 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

支付宝的Activity:

1 2 3 4 5 6 7 8 9 <!-- alipay sdk begin -->         <activity             android:name="com.alipay.sdk.app.H5PayActivity"             android:configChanges="orientation|keyboardHidden|navigation"             android:exported="false"             android:screenOrientation="behind"             android:windowSoftInputMode="adjustResize|stateHidden" >         </activity> <!-- alipay sdk end -->

到此为止支付宝sdk导入工程的工作算是完成了,接下来就是使用sdk完成付费了。

虽然破坏了java的封装性,但是为了方便起见我还是将支付宝的使用写到了一个java文件里了,我把使用放到了工程自带的HelloCpp.java文件中了,代码如/****************************************************************************Copyright (c) 2010-2012 cocos2d-x.orghttp://www.cocos2d-x.org

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ package org.cocos2dx.hellocpp2;   import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.Random;  
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。