在肯尼亚,现在蔓延到非洲和世界其他地方,我们有一种神奇的方式通过手机发送和接收资金,发明了移动货币。两家领先的服务提供商Safaricom和Airtel拥有各自的移动货币平台,分别是Mpesa和AirtelMoney。
由于在肯尼亚没有谷歌招商服务,而且使用这些服务也会让潜在的消费者望而却步,我一直在考虑用美比萨和AirtelMoney把我的应用卖给用户。现在,无论何时发生事务,Mobile服务都会向发送方和接收方发送确认短信。
现在,我将如何在我的应用程序上使用这个服务,因为我一直没有成功地使用可用的app,这些app使用的是web平台和其他技术。我的用户并不是每天都使用互联网,因为我的应用程序是教会成员使用的。但可以肯定的是,他们每天都会使用移动货币。我将感谢为此所作的任何努力。
我希望我的应用程序能够在用户通过Mpesa支付我的费用时,从试用更改到溢价,因为与web api相比,使用sms似乎更容易。
发布于 2016-11-05 03:00:25
我有一个类似的问题,并决定使用sms来实现这一目标。首先,我使用了允许我这样做的权限:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name="com.example.myapp.IncomingMessage"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS" >
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>在我的IncomingMessage活动中,我添加了以下代码:
package com.example.myapp;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
@SuppressLint("ShowToast")
public class IncomingMessage extends BroadcastReceiver
{
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context paramContext, Intent paramIntent)
{
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(paramContext.getApplicationContext()).edit();
if (!PreferenceManager.getDefaultSharedPreferences(paramContext.getApplicationContext()).getBoolean("js_vsb_is_paid", false))
{
Bundle localBundle = paramIntent.getExtras();
if (localBundle != null) {}
for (;;)
{
int i;
String sender;
String message;
try {
Object[] arrayOfObject = (Object[])localBundle.get("pdus");
i = 0;
if (i >= arrayOfObject.length) {
return;
}
SmsMessage localSmsMessage = SmsMessage.createFromPdu((byte[])arrayOfObject[i]);
sender = localSmsMessage.getDisplayOriginatingAddress();
message = localSmsMessage.getDisplayMessageBody();
Log.i("SmsReceiver", "senderNum: " + sender + "; message: " + message);
if (sender.equalsIgnoreCase("MPESA")) {
if (message.contains("JACKSON SIRO"))
{
editor.putBoolean("app_is_paid", true);
editor.commit();
//Toast.makeText(paramContext, "App Has been Activated!", Toast.LENGTH_LONG).show();
}
}
else if (sender.equalsIgnoreCase("AirtelMoney")) {
if (message.contains("JACKSON SIRO")) {
editor.putBoolean("app_is_paid", true);
editor.commit();
//Toast.makeText(paramContext, "App Has been Activated!", Toast.LENGTH_LONG).show();
}
}
} catch (Exception localException) {
Log.e("SmsReceiver", "Exception smsReceiver" + localException);
return;
}
}
}
}我希望这能帮到你。代码本身很简单,您可能会修改它以满足您的需要。
发布于 2017-12-05 14:26:03
Safaricom已经发布了M,作为RESTful API可以通过其开发人员门户访问。
Safaricom 存储库有一个使用Lipa na M-Pesa Online API的示例android应用。此API代表应用程序的用户启动M事务,用户只需输入他们的M即可完成事务。
https://stackoverflow.com/questions/40433067
复制相似问题