Android支付接入(三):电信爱游戏支付
原地址:http://blog.csdn.net/simdanfeg/article/details/9011977
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: [java] view plaincopy 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 [java] view plaincopy 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接入完成
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。