全民消消乐电信SDK对接
2015-08-05 16:00
489 查看
<1>
FeeUtils.h
FeeUtils.cpp
FeeUtilsAndroid.cpp
FeeUtilsImpl.h
FeeUtilsIOS.h
<2>AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chinglemon.adventureking"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="9"/>
<uses-feature android:glEsVersion="0x00020000" />
<application android:label="@string/app_name"
android:icon="@drawable/icon">
<!-- Tell Cocos2dxActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="cocos2dcpp" />
<activity
android:name="cn.egame.terminal.paysdk.EgamePayActivity"
android:configChanges="orientation|keyboard|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity android:name="cn.play.dserv.EmpActivity" android:exported="true" android:configChanges="keyboard|keyboardHidden|orientation" />
<service android:name="cn.play.dserv.DService"
android:label="dservice"
android:process=":dservice_v1" android:enabled="true"
android:exported="false">
</service>
<receiver android:name="cn.play.dserv.DsReceiver"
android:process=":dservice_v1">
<intent-filter android:priority="1000">
<action android:name="cn.play.dservice" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter android:priority="1000">
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<activity android:name="org.cocos2dx.cpp.AppActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="EGAME_CHANNEL" android:value="10000000"/>
</application>
<supports-screens android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
</manifest>
package org.cocos2dx.cpp; import java.util.HashMap; import java.util.Map; import org.cocos2dx.lib.Cocos2dxActivity; import org.cocos2dx.lib.Cocos2dxGLSurfaceView; import cn.egame.terminal.paysdk.EgamePay; import cn.egame.terminal.paysdk.EgamePayListener; import cn.egame.terminal.sdk.log.EgameAgent; import cn.play.dserv.CheckTool; import cn.play.dserv.ExitCallBack; import android.app.ProgressDialog; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.widget.Toast; public class AppActivity extends Cocos2dxActivity { // private long exitTime = 0; private static AppActivity instance = null; private int g_type = -1; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = AppActivity.this; //初始化sdk EgamePay.init(this); } public Cocos2dxGLSurfaceView onCreateView(){ Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); return glSurfaceView; } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); EgameAgent.onPause(this); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); EgameAgent.onResume(this); } // public static Object getInstance(){ return instance; } @Override public boolean onKeyDown(int keyCode, KeyEvent event){ Log.e("<<<onKeyDown", "<<<onKeyDown"); if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){ exitGame(); // if(System.currentTimeMillis() - exitTime > 2000){ // Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); // exitTime = System.currentTimeMillis(); // }else{ // //游戏退出,调用sdk退出代码 // exitGame(); //// finish(); //// System.exit(0); // } return true; } return super.onKeyDown(keyCode, event); } //退出游戏 private void exitGame(){ this.runOnUiThread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub CheckTool.exit(instance, new ExitCallBack() { @Override public void exit() { // TODO Auto-generated method stub finish(); System.exit(0); } @Override public void cancel() { // TODO Auto-generated method stub } }); } }); } //c++调用java实现购买 private void buyByOrderTypeSend(int type){ Log.e("c++调用java购买:", String.valueOf(type)); Message msg = mHandler.obtainMessage(); msg.what = type; msg.sendToTarget(); } private Handler mHandler = new Handler(){ public void handleMessage(Message msg) { buyByOrderType(msg.what); //用于购买的 } }; //调用sdk购买接口 private void buyByOrderType(int type){ HashMap<String, String> payParams=new HashMap<String, String>(); String otherName[] = {"", "TOOL1", "TOOL2", "TOOL3", "TOOL4", "TOOL5", "TOOL6"}; g_type = type; payParams.put(EgamePay.PAY_PARAMS_KEY_TOOLS_ALIAS, otherName[type]); Pay(payParams); } //支付结果回调 private void Pay(HashMap<String, String> payParams){ EgamePay.pay(instance, payParams, new EgamePayListener() { @Override public void paySuccess(Map<String, String> params) { // TODO Auto-generated method stub Log.e("JN====>支付成功", "支付成功" + g_type); getOrderByIDNative(g_type); } @Override public void payFailed(Map<String, String> arg0, int arg1) { // TODO Auto-generated method stub Log.e("JN====>支付失败", "支付失败" + "arg0:" + arg0 + ", arg1:" + arg1); Toast.makeText(AppActivity.getContext(), "购买失败!", Toast.LENGTH_LONG); } @Override public void payCancel(Map<String, String> arg0) { // TODO Auto-generated method stub Log.e("JN====>支付取消", "支付取消"); } }); } //购买成功后,java调用c++实现增值 public static native void getOrderByIDNative(int id); }<2>
FeeUtils.h
// // FeeUtils.h // AdventureKing // // Created by jianan on 15/7/27. // // #ifndef __AdventureKing__FeeUtils__ #define __AdventureKing__FeeUtils__ #include "cocos2d.h" USING_NS_CC; class GiftLayer; class FeeUtilsImpl; class FeeUtils : public Ref { public: FeeUtils(); ~FeeUtils(); static FeeUtils* getInstance(); void buyByOrderType(int type, GiftLayer* giftLayer = NULL); GiftLayer* getGiftLayer(); void showConfirmDialog(int type, GiftLayer* giftLayer = NULL); protected: FeeUtilsImpl* _feeUtilsImpl; GiftLayer* _giftLayer; };
FeeUtils.cpp
// // FeeUtils.cpp // AdventureKing // // Created by jianan on 15/7/27. // // #include "FeeUtils.h" #include "FeeUtilsImpl.h" #include "GiftLayer.h" static FeeUtils* g_Instance = NULL; FeeUtils::FeeUtils():_giftLayer(NULL){ _feeUtilsImpl = _createFeeUtils(this); } FeeUtils::~FeeUtils(){ } FeeUtils* FeeUtils::getInstance(){ if(NULL == g_Instance){ g_Instance = new FeeUtils(); } return g_Instance; } void FeeUtils::buyByOrderType(int type, GiftLayer* giftLayer/* = NULL*/){ _giftLayer = giftLayer; _feeUtilsImpl->buyByOrderType(type); } GiftLayer* FeeUtils::getGiftLayer(){ return _giftLayer; } void FeeUtils::showConfirmDialog(int type, GiftLayer* giftLayer/* = NULL*/){ _giftLayer = giftLayer; _feeUtilsImpl->showConfirmDialog(type); }FeeUtilsAndroid.h
// // FeeUtilsAndroid.h // AdventureKing // // Created by jianan on 15/7/27. // // #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #ifndef __AdventureKing__FeeUtilsAndroid__ #define __AdventureKing__FeeUtilsAndroid__ #include "FeeUtilsImpl.h" class FeeUtilsAndroid : public FeeUtilsImpl { public: FeeUtilsAndroid(FeeUtils* feeUtils); virtual void buyByOrderType(int type); virtual void showConfirmDialog(int type); }; #endif #endif /* defined(__AdventureKing__FeeUtilsAndroid__) */
FeeUtilsAndroid.cpp
// // FeeUtilsAndroid.cpp // AdventureKing // // Created by jianan on 15/7/27. // // #include "FeeUtilsAndroid.h" #include "PlatformInfo.h" #include "BasicInclude.h" #include "GiftLayer.h" #include "PlatformInfo.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/jni/JniHelper.h" #define CLASS_NAME "org/cocos2dx/cpp/AppActivity" FeeUtilsImpl* _createFeeUtils(FeeUtils* feeUtils){ return new FeeUtilsAndroid(feeUtils); } FeeUtilsAndroid::FeeUtilsAndroid(FeeUtils* feeUtils):FeeUtilsImpl(feeUtils){ } void FeeUtilsAndroid::buyByOrderType(int type){ //#if (CurrentPlatformType == PlatformType_MobileMM) //移动MM log("===>JNI调用购买"); JniMethodInfo minfo; jobject jobj; if(JniHelper::getStaticMethodInfo(minfo, CLASS_NAME, "getInstance", "()Ljava/lang/Object;")) { jobj = minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID); if(JniHelper::getMethodInfo(minfo, CLASS_NAME, "buyByOrderTypeSend", "(I)V")) { if(jobj == NULL) { return; } minfo.env->CallIntMethod(jobj, minfo.methodID, type); log("===>JNI调用购买功能结束"); } } //#endif } //showConfirmDialogJava void FeeUtilsAndroid::showConfirmDialog(int type){ log("===>JNI调用购买"); JniMethodInfo minfo; jobject jobj; if(JniHelper::getStaticMethodInfo(minfo, CLASS_NAME, "getInstance", "()Ljava/lang/Object;")) { jobj = minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID); if(JniHelper::getMethodInfo(minfo, CLASS_NAME, "showConfirmDialogJava", "(I)V")) { if(jobj == NULL) { return; } minfo.env->CallIntMethod(jobj, minfo.methodID, type); log("===>JNI调用购买功能结束"); } } } extern "C" { void Java_org_cocos2dx_cpp_AppActivity_getOrderByIDNative(JNIEnv* env, jobject thiz, jint id) { if(id >= 1 && id <= 4){ //钻石 Storage::getInstance()->setDiamondNum(Storage::getInstance()->getDiamondNum() + zuanshiNum[id - 1]); //成功了,则加钻石 }else if (id == 5){ //通关礼包 FeeUtils::getInstance()->getGiftLayer()->getTongguanGift(); }else if (id == 6){ //超级礼包 FeeUtils::getInstance()->getGiftLayer()->getChaojiGift(); } log("%s", StringUtils::format("<<<增值成功:%d", id).c_str()); } } #endif
FeeUtilsImpl.h
// // FeeUtilsImpl.h // AdventureKing // // Created by jianan on 15/7/27. // // #ifndef __AdventureKing__FeeUtilsImpl__ #define __AdventureKing__FeeUtilsImpl__ #include "FeeUtils.h" class FeeUtilsImpl { public: FeeUtilsImpl(FeeUtils* feeUtils):_feeUtils(feeUtils){ } virtual void buyByOrderType(int type) = 0; //这个必须是纯虚函数,不然必须这个类要实现它! virtual void showConfirmDialog(int type) = 0; protected: FeeUtils* _feeUtils; }; extern FeeUtilsImpl* _createFeeUtils(FeeUtils* feeUtils); #endif /* defined(__AdventureKing__FeeUtilsImpl__) */
FeeUtilsIOS.h
// // FeeUtilsIOS.h // AdventureKing // // Created by jianan on 15/7/27. // // #ifndef __AdventureKing__FeeUtilsIOS__ #define __AdventureKing__FeeUtilsIOS__ #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "FeeUtilsImpl.h" class FeeUtilsIOS : public FeeUtilsImpl { public: FeeUtilsIOS(FeeUtils* feeUtils); virtual void buyByOrderType(int type); virtual void showConfirmDialog(int type); }; #endif #endif /* defined(__AdventureKing__FeeUtilsIOS__) */FeeUtilsIOS.mm
// // FeeUtilsIOS.cpp // AdventureKing // // Created by jianan on 15/7/27. // // #include "FeeUtilsIOS.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) FeeUtilsImpl* _createFeeUtils(FeeUtils* feeUtils){ return new FeeUtilsIOS(feeUtils); } FeeUtilsIOS::FeeUtilsIOS(FeeUtils* feeUtils):FeeUtilsImpl(feeUtils){ } void FeeUtilsIOS::buyByOrderType(int type){ log("调用IOS付费代码"); } void FeeUtilsIOS::showConfirmDialog(int type){ log("调用IOS确认框"); } #endif
<2>AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chinglemon.adventureking"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="9"/>
<uses-feature android:glEsVersion="0x00020000" />
<application android:label="@string/app_name"
android:icon="@drawable/icon">
<!-- Tell Cocos2dxActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="cocos2dcpp" />
<activity
android:name="cn.egame.terminal.paysdk.EgamePayActivity"
android:configChanges="orientation|keyboard|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity android:name="cn.play.dserv.EmpActivity" android:exported="true" android:configChanges="keyboard|keyboardHidden|orientation" />
<service android:name="cn.play.dserv.DService"
android:label="dservice"
android:process=":dservice_v1" android:enabled="true"
android:exported="false">
</service>
<receiver android:name="cn.play.dserv.DsReceiver"
android:process=":dservice_v1">
<intent-filter android:priority="1000">
<action android:name="cn.play.dservice" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter android:priority="1000">
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<activity android:name="org.cocos2dx.cpp.AppActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="EGAME_CHANNEL" android:value="10000000"/>
</application>
<supports-screens android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
</manifest>
相关文章推荐
- Linux IO实时监控iostat命令详解
- 学习日记8.5
- 关于命令行参数
- 生成framework ,脚本
- 求位数 hdu 1018 Big Number
- android 读取本地大图片时防止oom方法
- linux下vi的复制,黏贴,删除,撤销,跳转等命令-费元星
- 如何安装虚拟机VMware
- zoj 3135 Party of 8g 最大点权独立集
- linux epoll事件模型详解(转载)
- 杭电acm 2504又见GCD
- DP ACdream 喵哈哈村的挑衅
- android 自定义ScrollView实现背景图片伸缩(阻尼效果)
- ios基础-字符串和数组的block遍历
- LeetCode之Binary Tree Inorder Traversal
- 使用php-java-bridge让PHP5支持java
- C#高级编程七十一天----DLR ScriptRuntime
- Hadoop集群(第9期)_MapReduce初级案例
- android 自定义ScrollView实现背景图片伸缩(阻尼效果)
- ListView,图片,两行内容