Android支付接入(五):机锋网
1.界面的頻繁跳轉(zhuǎn)會(huì)費(fèi)時(shí)(尤其對(duì)于用cocos2d-x寫(xiě)的游戲來(lái)說(shuō)界面跳出跳進(jìn)延時(shí)非常大,會(huì)影響游戲性);
2.開(kāi)啟新Activity會(huì)涉及到數(shù)據(jù)的傳遞,新Activity的維護(hù)及銷(xiāo)毀,這里力求簡(jiǎn)潔,頻繁的數(shù)據(jù)傳遞難免會(huì)出錯(cuò)(大家都知道,支付的邏輯是不同意出現(xiàn)丁點(diǎn)錯(cuò)誤的),假設(shè)單一渠道的付費(fèi)邏輯上非常easy,假設(shè)集合了5、6個(gè)甚至很多其它的付費(fèi)方式的時(shí)候以及摻雜游戲邏輯之后,支付邏輯不夠簡(jiǎn)潔會(huì)使你頭疼。
3.正在嘗試的讓cocos2d-x的游戲跟Unity3D的游戲使用一套付費(fèi)接口,這種話(huà)Activity多了不會(huì)是一個(gè)好的選擇
4.假設(shè)使用Activity那么AndroidManifest里邊必須要注意注冊(cè)此Activity,這是一個(gè)定時(shí)炸彈,由于不同支付方式都須要在Manifest里邊注冊(cè)相關(guān)配置,當(dāng)配置量大了以后難免會(huì)漏掉次Activity的聲明,SDK的接入是批量的你可能會(huì)同一時(shí)候接不同的游戲和不同的付費(fèi)方式,這就須要在最短的時(shí)間里準(zhǔn)確的接好多種游戲及付費(fèi)方式,因此注意事項(xiàng)越少越好。
?
機(jī)鋒的支付是比較簡(jiǎn)單的一種支付方式,并且其本身已經(jīng)集成了支付寶和充值卡支付,如今我們來(lái)看下代碼:
AndroiManifest.xml
[html] view plaincopy- <!--?機(jī)鋒網(wǎng)?-->??
- ????????<activity??
- ????????????android:name="com.gfan.sdk.payment.PaymentsActivity"??
- ????????????android:configChanges="orientation|keyboardHidden"?/>??
- ????????<activity??
- ????????????android:name="com.gfan.sdk.charge.ChargeActivity"??
- ????????????android:configChanges="orientation|keyboardHidden"?/>??
- ????????<activity??
- ????????????android:name="com.gfan.sdk.account.LoginActivity"??
- ????????????android:configChanges="orientation|keyboardHidden"??
- ????????????android:windowSoftInputMode="adjustUnspecified"?/>??
- ??
- ????????<!--?請(qǐng)?zhí)鎿Qgfan_pay_appkey為開(kāi)發(fā)人員平臺(tái)中的appKey?-->??
- ????????<meta-data??
- ????????????android:name="gfan_pay_appkey"??
- ????????????android:value="XXX"?/>??
- ??
- ????????<!--?不用動(dòng)?-->??
- ????????<meta-data??
- ????????????android:name="gfan_type"??
- ????????????android:value="paysdk"?/>??
- ??
- ????????<!--?不用動(dòng)?-->??
- ????????<meta-data??
- ????????????android:name="gfan_cpid"??
- ????????????android:value="testcpid"?/>??
- ??
- <!--這里是Activity的聲明及機(jī)鋒參數(shù)配置-->??
- ???
- ??
- ????<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"/>??
- ??
- <!--權(quán)限的配置,第三方平臺(tái)支付都是走的網(wǎng)絡(luò),所以須要聯(lián)網(wǎng)權(quán)限,及獲取是否聯(lián)網(wǎng)的權(quán)限-->??
?
Fiap.java
?
[java] view plaincopy- package?com.example.blogforgfan;??
- ??
- //?機(jī)鋒應(yīng)用內(nèi)支付??
- import?com.gfan.sdk.payment.PaymentInfo;??
- import?com.gfan.sdk.payment.PaymentsActivity;??
- import?android.annotation.SuppressLint;??
- import?android.app.Activity;??
- import?android.app.AlertDialog;??
- import?android.content.Context;??
- import?android.content.Intent;??
- import?android.net.ConnectivityManager;??
- import?android.net.NetworkInfo;??
- import?android.os.Bundle;??
- import?android.os.Handler;??
- import?android.view.View;??
- ??
- @SuppressLint("HandlerLeak")??
- public?class?Fiap?extends?Activity?{??
- ??
- ????final?int?CATCAP_ANDROID_PAY?=?0;?//?跳轉(zhuǎn)Activity請(qǐng)求碼??
- ????int?catcap_android_pay_catcap_coin?=?0;?//?購(gòu)買(mǎi)的貓幣??
- ??
- ????@Override??
- ????protected?void?onCreate(Bundle?savedInstanceState)?{??
- ????????//?TODO?Auto-generated?method?stub??
- ????????super.onCreate(savedInstanceState);??
- ????????setContentView(R.layout.activity_main);??
- ????????findViewById(R.id.button1).setOnClickListener(??
- ????????????????new?View.OnClickListener()?{??
- ??
- ????????????????????@Override??
- ????????????????????public?void?onClick(View?v)?{??
- ????????????????????????//?TODO?Auto-generated?method?stub??
- ????????????????????????android_pay(2);??
- ????????????????????}??
- ????????????????});??
- ????}??
- ??
- ????//?===================================??
- ????//?JAVA??
- ????//?===================================??
- ??
- ????public?void?android_pay(int?index)?{??
- ????????if?(!is_can_internet(Fiap.this))?{??
- ????????????fiapHandler.sendEmptyMessage(1);??
- ????????????return;??
- ????????}??
- ????????int?coin?=?0;??
- ????????switch?(index)?{??
- ????????case?0:??
- ????????????coin?=?2;??
- ????????????this.catcap_android_pay_catcap_coin?=?50;??
- ????????????break;??
- ????????case?1:??
- ????????????coin?=?4;??
- ????????????this.catcap_android_pay_catcap_coin?=?120;??
- ????????????break;??
- ????????case?2:??
- ????????????coin?=?6;??
- ????????????this.catcap_android_pay_catcap_coin?=?200;??
- ????????????break;??
- ????????case?3:??
- ????????????coin?=?8;??
- ????????????this.catcap_android_pay_catcap_coin?=?300;??
- ????????????break;??
- ??
- ????????default:??
- ????????????break;??
- ????????}??
- ????????//?coin?*=?10;此處coin是人民幣,換算成機(jī)鋒券需*10??
- ????????//?設(shè)置購(gòu)買(mǎi)信息(購(gòu)買(mǎi)的道具名,付費(fèi)描寫(xiě)敘述,支付金額,訂單號(hào))??
- ????????//?PS:這里須要自己組織訂單號(hào),所以需保證每次訂單號(hào)是唯一的,此處傳入的金額是機(jī)鋒券(1元=10機(jī)鋒券)??
- ????????PaymentInfo?info?=?new?PaymentInfo("貓幣",?"購(gòu)買(mǎi)游戲所用貓幣",?coin,??
- ????????????????get_order_id());??
- ????????//?到購(gòu)買(mǎi)頁(yè)面??
- ????????Intent?intent?=?new?Intent(this,?PaymentsActivity.class);??
- ????????intent.putExtra(PaymentsActivity.EXTRA_KEY_PAYMENTINFO,?info);??
- ????????startActivityForResult(intent,?CATCAP_ANDROID_PAY);??
- ????}??
- ??
- ????//?===================================??
- ????//?Android??
- ????//?===================================??
- ????@Override??
- ????protected?void?onActivityResult(int?requestCode,?int?resultCode,?Intent?data)?{??
- ????????if?(requestCode?==?CATCAP_ANDROID_PAY)?{?//?保證結(jié)果碼跟請(qǐng)求碼一致??
- ????????????if?(resultCode?==?RESULT_OK)?{?//?支付成功,這里填寫(xiě)支付成功后的邏輯??
- ??
- ????????????????new?AlertDialog.Builder(this).setTitle("感謝購(gòu)買(mǎi)貓幣")??
- ????????????????????????.setPositiveButton("確定",?null).create().show();??
- ??
- ????????????}??
- ????????}??
- ????????//?清空數(shù)據(jù)??
- ????????this.catcap_android_pay_catcap_coin?=?0;??
- ????????super.onActivityResult(requestCode,?resultCode,?data);??
- ????}??
- ??
- ????public?boolean?is_can_internet(final?Context?context)?{??
- ????????try?{??
- ????????????ConnectivityManager?manger?=?(ConnectivityManager)?context??
- ????????????????????.getSystemService(Context.CONNECTIVITY_SERVICE);??
- ????????????NetworkInfo?info?=?manger.getActiveNetworkInfo();??
- ????????????return?(info?!=?null?&&?info.isConnected());??
- ????????}?catch?(Exception?e)?{??
- ????????????return?false;??
- ????????}??
- ????}??
- ??
- ????public?String?get_order_id()?{??
- ????????long?ran1?=?get_round(1111,?9999);??
- ????????long?ran2?=?get_round(1111,?9999);??
- ????????//?return?android_get_umeng_channel?()?+?"_"?+?ran1?+??
- ????????//?System.currentTimeMillis?()?+?ran2;??
- ????????return?"_"?+?ran1?+?System.currentTimeMillis()?+?ran2;??
- ????}??
- ??
- ????public?long?get_round(int?min,?int?max)?{??
- ????????return?Math.round(Math.random()?*?(max?-?min)?+?min);??
- ????}??
- ??
- ????Handler?fiapHandler?=?new?Handler()?{??
- ??
- ????????public?void?handleMessage(android.os.Message?msg)?{??
- ????????????if?(msg.what?==?1)?{??
- ????????????????new?AlertDialog.Builder(Fiap.this).setTitle("提示")??
- ????????????????????????.setMessage("連接不到網(wǎng)絡(luò)。").setPositiveButton("確定",?null)??
- ????????????????????????.create().show();??
- ????????????}??
- ????????};??
- ????};??
- }??
?
轉(zhuǎn)載于:https://www.cnblogs.com/mfrbuaa/p/3852707.html
總結(jié)
以上是生活随笔為你收集整理的Android支付接入(五):机锋网的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 关于mysql字符集及导入导出
- 下一篇: hdu 2028 Lowest Comm