当前位置: 代码迷 >> Android >> Android支付接入(3):电信爱游戏支付
  详细解决方案

Android支付接入(3):电信爱游戏支付

热度:62   发布时间:2016-04-28 08:16:22.0
Android支付接入(三):电信爱游戏支付
刚过完51,公司还没什么气氛,人好少啊。。。好了废话不多说了,今天跟大家一起走一遍电信的爱游戏支付。其实三大运营商的支付接口是类似的,均以付费计费点短代码标识计费,然后调用支付接口,实现支付结果回调,上一篇跟大家一起走了一遍移动的支付可以看的出来运营商的支付逻辑是很简单的,只是界面、功能点的要求比较多,电信计费跟移动一样我会为大家整理好付费接入要求。文中所用到的资源及demo照旧放到了百度网盘中,地址:http://pan.baidu.com/share/link?shareid=429716&uk=473193131

注意事项:
1.电信要求必须先启动电信的闪屏界面
2.非网络游戏不允许有Interent权限
3.电信没有提供测试计费点(小于一元的),文中index1是一个真实计费点(2元),支付会进行真实计费

上代码:

AndroidManifest.xml:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.blogfordx.MainActivity"
            android:label="@string/app_name" >
            
        </activity>
        
        <!-- 电信 -->
<activity android:name="cn.game189.sms.SMS" android:theme="@android:style/Theme.Dialog" android:screenOrientation="portrait" ></activity>
<!-- 电信 -->
<!-- 启动闪屏界面 -->
<activity
            android:name="com.example.blogfordx.EgameSplash"
            android:configChanges="orientation"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    
    <!-- 单机游戏不能有Internet等无关权限,若有特殊要求,平台申请时注明,审核通过后方可添加 -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SEND_SMS" />

MainActivity.java:

package com.example.blogfordx;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
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
Fiap fiap = new Fiap(MainActivity.this);
fiap.android_Pay(1);
}
});
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//更多游戏接口
Uri uri = Uri.parse("http://wapgame.189.cn/c/index.html");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
MainActivity.this.startActivity(in);
}
});
}

}

EgameSplash.java:

package com.example.blogfordx;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class EgameSplash extends Activity{
private int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while(count <= 2){
count ++ ;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Intent intent = new Intent(EgameSplash.this,MainActivity.class);
startActivity(intent);
EgameSplash.this.finish();
}
}).start();
}
}

Fiap.java:

package com.example.blogfordx;

import cn.game189.sms.SMS;
import cn.game189.sms.SMSListener;
import android.app.Activity;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

public class Fiap {
private Activity mActivity;
//是否允许重复计费
private boolean isRepeat;
//计费点短代码
private String charge_Point;
//道具名称
private String itemID = "";
//支付金额
private int coin = 0;
public Fiap(Activity activity){
mActivity = activity;
}
//index是三种计费点对应的标识
//此处只有购买200兑换币是可支付的,正式使用时请填写自己的申请的计费点短代码
public void android_Pay(int index){
switch (index) {

case 0:
//激活游戏
isRepeat = false;
//此处计费点填写电信平台申请的计费点的后三位作为计费点索引
charge_Point = "000";
itemID = "激活游戏";
coin = 4;
break;
case 1:
isRepeat = true;
charge_Point = "0211C001271102517996991102517990080115127000000000000000000000000000";
itemID = "购买200兑换币";
coin = 2;
break;
case 2:
isRepeat = true;
charge_Point = "002";
itemID = "购买400兑换币";
coin = 3;
break;

default:
break;
}
fiapHandler.sendEmptyMessage(1);
}
Handler fiapHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
if (msg.what == 1) {
if (SMS.checkFee(itemID, mActivity, new SMSListener() {

public void smsOK(String feeName) {
// 短代发送成功,此处填写支付成功后的逻辑
Log.i("SMSListener", "模式" + feeName + "已计费完成,关卡已打开.");
Toast.makeText(mActivity, "支付成功", Toast.LENGTH_LONG).show();
}

public void smsFail(String feeName, int errorCode) {
// 短代发送失败,不给道具或不放行关卡
Log.e("SMSListener", "计费失败!模式:[" + feeName + "] 错误码:" + errorCode);
}

public void smsCancel(String feeName, int errorCode) {
Log.e("SMSListener", "用户点击取消!计费点:" + feeName + " 错误码:"+ errorCode );
}
}, charge_Point, itemID + ",点击确定将会发送一条"+ coin + "元短信,不含信息费.", "短信已成功发送", isRepeat)) {
// 已计过费

}
}
};
};

}

   至此,电信的计费sdk接入完成,可以看得出跟移动的计费流程区别不大,只是接口和细节有些差别,下一篇我们来接一下联通计费
  相关解决方案