网站托管 域名,网站功能怎么写,网站建设中网站需求分析和报告工能论文,如何自己建设简单的手机网站首页本文主要介绍国外google上线的app 短信自动填充方案。
本方案主要是使用google提出的#xff0c;防止开发者使用SMS相关权限造成的用户信息泄露
目录
注意点#xff1a;
1、本方式不适合华为手机#xff0c;华为有自己的获取方式
2、本方式不需要添加任何短信权限
3、…本文主要介绍国外google上线的app 短信自动填充方案。
本方案主要是使用google提出的防止开发者使用SMS相关权限造成的用户信息泄露
目录
注意点
1、本方式不适合华为手机华为有自己的获取方式
2、本方式不需要添加任何短信权限
3、项目版本
开发成本
Android代码
1、导库
1在项目根目录的build.gradle中添加下面代码
2项目级build.gradle引用库
2、注册广播
1静态注册
2动态注册
3、启动监听
4、广播代码
其他开发成本
短信模板 短信后i按加上11位哈市值
1命令mac 命令
2代码放入项目中运行打包、启动app注意debug签名与正是签名包的不同正式的hashcode 需要正式打包然后打印出来 注意点
1、本方式不适合华为手机华为有自己的获取方式
2、本方式不需要添加任何短信权限
3、项目版本 compileSdkVersion34 minSdkVersion19 开发成本
app需要集成两个google库后端只需要改短信模板在短信后面添加11位hash值hash值生成方式在下面链接可以看到
google开发地址国内需要翻墙
Android代码 1、导库
1在项目根目录的build.gradle中添加下面代码
buildscript {repositories {...google()mavenCentral()}
}allprojects {repositories { google()mavenCentral()}
} 2项目级build.gradle引用库
dependencies {implementation com.google.android.gms:play-services-auth:21.2.0implementation com.google.android.gms:play-services-auth-api-phone:18.1.0
}
2、注册广播
1静态注册 receiverandroid:name路径.MySMSBroadcastReceiverandroid:exportedtrueandroid:permissioncom.google.android.gms.auth.api.phone.permission.SENDintent-filteraction android:namecom.google.android.gms.auth.api.phone.SMS_RETRIEVED //intent-filter/receiver
2动态注册 if(smsBrodnull){smsBrod MySMSBroadcastReceiver(this,null)}val intentFilter IntentFilter();intentFilter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION);if (Build.VERSION.SDK_INT Build.VERSION_CODES.O) {thisTestAlendActivity.registerReceiver(smsBrod,intentFilter,SmsRetriever.SEND_PERMISSION,null, Context.RECEIVER_EXPORTED)}
3、启动监听 fun googleMSM() {val client SmsRetriever.getClient(this)val task: TaskVoid client.startSmsRetriever()task.addOnSuccessListener(OnSuccessListenerVoid? {Log.i(SMS_CON, googleMSM addOnSuccessListener)if(smsBrodnull){smsBrod MySMSBroadcastReceiver(this,null)}val intentFilter IntentFilter();intentFilter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION);if (Build.VERSION.SDK_INT Build.VERSION_CODES.O) {thisTestAlendActivity.registerReceiver(smsBrod,intentFilter,SmsRetriever.SEND_PERMISSION,null, Context.RECEIVER_EXPORTED)}})task.addOnFailureListener(OnFailureListener {Log.i(SMS_CON, googleMSM addOnFailureListener)})}
4、广播代码 import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;import com.google.android.gms.auth.api.phone.SmsRetriever;
import com.google.android.gms.common.api.CommonStatusCodes;
import com.google.android.gms.common.api.Status;import org.json.JSONException;
import org.json.JSONObject;import java.lang.ref.SoftReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;/*** BroadcastReceiver to wait for SMS messages. This can be registered either* in the AndroidManifest or at runtime. Should filter Intents on* SmsRetriever.SMS_RETRIEVED_ACTION.*/
public class MySMSBroadcastReceiver extends BroadcastReceiver {public MySMSBroadcastReceiver() {}Overridepublic void onReceive(Context context, Intent intent) {Log.i(SMS_CON, googleMSM MySMSBroadcastReceiver action intent.getAction());if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {Bundle extras intent.getExtras();Status status (Status) extras.get(SmsRetriever.EXTRA_STATUS);Log.i(SMS_CON, status status);if(status!null){switch (status.getStatusCode()) {case CommonStatusCodes.SUCCESS:// (Optional) Get SMS Sender address - only available in// GMS version 24.20 onwards, else it will return null
// String senderAddress extras.getString(SmsRetriever.EXTRA_SMS_ORIGINATING_ADDRESS);// Get SMS message contentsString message extras.getString(SmsRetriever.EXTRA_SMS_MESSAGE);// Extract one-time code from the message and complete verification// by sending the code back to your server.Log.i(SMS_CON, message message);if (message ! null) {Pattern code Pattern.compile((\\d{6}));Matcher matcher code.matcher(message);String otp ;if (matcher.find()) {otp matcher.group(0);} else {otp message;}Log.i(SMS_CON, otp otp);Toast.makeText(context,otp\notp,Toast.LENGTH_LONG).show();}break;case CommonStatusCodes.TIMEOUT:// Waiting for SMS timed out (5 minutes)// Handle the error ...Log.i(SMS_CON, TIMEOUT );break;}}}}
}
其他开发成本
短信模板 短信后i按加上11位哈市值
Hash值生成方式
1命令mac 命令 keytool -exportcert -keystore keystory名称.jks -storepass 你的密码 -alias 别名 | xxd -p | tr -d [:space:] | echo -n 你的包名 cat | shasum -a 256 | tr -d [:space:]- | xxd -r -p | base64 | cut -c1-11 2代码放入项目中运行打包、启动app注意debug签名与正是签名包的不同正式的hashcode 需要正式打包然后打印出来
aab文件也可以通过命令安装到手机网上搜一下 bundletool.jar 这个工具 import android.annotation.TargetApi;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;public class AppSignatureHashHelper extends ContextWrapper {public static final String TAG AppSignatureHashHelper.class.getSimpleName();private static final String HASH_TYPE SHA-256;public static final int NUM_HASHED_BYTES 9;public static final int NUM_BASE64_CHAR 11;public AppSignatureHashHelper(Context context) {super(context);}public ArrayListString getAppSignatures() {ArrayListString appSignaturesHashs new ArrayList();try {String packageName getPackageName();PackageManager packageManager getPackageManager();Signature[] signatures packageManager.getPackageInfo(packageName,PackageManager.GET_SIGNATURES).signatures;for (Signature signature : signatures) {String hash hash(packageName, signature.toCharsString());if (hash ! null) {appSignaturesHashs.add(String.format(%s, hash));}}} catch (Exception e) {Log.e(TAG, Package not found, e);}return appSignaturesHashs;}TargetApi(19)private static String hash(String packageName, String signature) {String appInfo packageName signature;try {MessageDigest messageDigest MessageDigest.getInstance(HASH_TYPE);messageDigest.update(appInfo.getBytes(StandardCharsets.UTF_8));byte[] hashSignature messageDigest.digest();hashSignature Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);String base64Hash Base64.encodeToString(hashSignature, Base64.NO_PADDING | Base64.NO_WRAP);base64Hash base64Hash.substring(0, NUM_BASE64_CHAR);return base64Hash;} catch (NoSuchAlgorithmException e) {Log.e(TAG, No Such Algorithm Exception, e);}return null;}
}
调用方式 String hashcodeStr AppSignatureHashHelper(this).getAppSignatures() 上面会生成11位hash值放在短信后面就行了
***以上是获取短信短信自动填充代码就不写了拿到字符串 设置到输入框就行推荐按使用动态注册可以给广播传入回调接口处理返回的验证码otp
到这里就完成了上面获取命令的方式是通过自己签名的方式如果是让google生成签名则需要去看链接里的步骤比较详细
测试的话 可以让别人发短信给你 在app里会受到广播 文章转载自: http://www.morning.wlstn.cn.gov.cn.wlstn.cn http://www.morning.mpgfk.cn.gov.cn.mpgfk.cn http://www.morning.nzkc.cn.gov.cn.nzkc.cn http://www.morning.nba1on1.com.gov.cn.nba1on1.com http://www.morning.bmnm.cn.gov.cn.bmnm.cn http://www.morning.wzdjl.cn.gov.cn.wzdjl.cn http://www.morning.qbrdg.cn.gov.cn.qbrdg.cn http://www.morning.tsdjj.cn.gov.cn.tsdjj.cn http://www.morning.xqjh.cn.gov.cn.xqjh.cn http://www.morning.jxhlx.cn.gov.cn.jxhlx.cn http://www.morning.xhhqd.cn.gov.cn.xhhqd.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.sftrt.cn.gov.cn.sftrt.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.lphtm.cn.gov.cn.lphtm.cn http://www.morning.rbtny.cn.gov.cn.rbtny.cn http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.pphbn.cn.gov.cn.pphbn.cn http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn http://www.morning.fpjxs.cn.gov.cn.fpjxs.cn http://www.morning.mgtrc.cn.gov.cn.mgtrc.cn http://www.morning.yjfzk.cn.gov.cn.yjfzk.cn http://www.morning.syznh.cn.gov.cn.syznh.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.qnrpj.cn.gov.cn.qnrpj.cn http://www.morning.btqqh.cn.gov.cn.btqqh.cn http://www.morning.duqianw.com.gov.cn.duqianw.com http://www.morning.youyouling.cn.gov.cn.youyouling.cn http://www.morning.rmryl.cn.gov.cn.rmryl.cn http://www.morning.xwbld.cn.gov.cn.xwbld.cn http://www.morning.cndxl.cn.gov.cn.cndxl.cn http://www.morning.pxwjp.cn.gov.cn.pxwjp.cn http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.ryfqj.cn.gov.cn.ryfqj.cn http://www.morning.bxczt.cn.gov.cn.bxczt.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.wnkbf.cn.gov.cn.wnkbf.cn http://www.morning.wljzr.cn.gov.cn.wljzr.cn http://www.morning.wmqrn.cn.gov.cn.wmqrn.cn http://www.morning.nmfwm.cn.gov.cn.nmfwm.cn http://www.morning.prxqd.cn.gov.cn.prxqd.cn http://www.morning.rjcqb.cn.gov.cn.rjcqb.cn http://www.morning.lchtb.cn.gov.cn.lchtb.cn http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn http://www.morning.rlhjg.cn.gov.cn.rlhjg.cn http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn http://www.morning.njstzsh.com.gov.cn.njstzsh.com http://www.morning.kjawz.cn.gov.cn.kjawz.cn http://www.morning.njftk.cn.gov.cn.njftk.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.prhfc.cn.gov.cn.prhfc.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.ltypx.cn.gov.cn.ltypx.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.ljngm.cn.gov.cn.ljngm.cn http://www.morning.cmhkt.cn.gov.cn.cmhkt.cn http://www.morning.ghcfx.cn.gov.cn.ghcfx.cn http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.shyqcgw.cn.gov.cn.shyqcgw.cn http://www.morning.qqnjr.cn.gov.cn.qqnjr.cn http://www.morning.bysey.com.gov.cn.bysey.com http://www.morning.kszkm.cn.gov.cn.kszkm.cn http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn http://www.morning.lyhry.cn.gov.cn.lyhry.cn http://www.morning.zgdnz.cn.gov.cn.zgdnz.cn http://www.morning.c7623.cn.gov.cn.c7623.cn http://www.morning.jrqw.cn.gov.cn.jrqw.cn http://www.morning.sjsfw.cn.gov.cn.sjsfw.cn http://www.morning.jypqx.cn.gov.cn.jypqx.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.xkppj.cn.gov.cn.xkppj.cn http://www.morning.nbdtdjk.cn.gov.cn.nbdtdjk.cn http://www.morning.btqqh.cn.gov.cn.btqqh.cn http://www.morning.lgwjh.cn.gov.cn.lgwjh.cn http://www.morning.fgtls.cn.gov.cn.fgtls.cn http://www.morning.yfrlk.cn.gov.cn.yfrlk.cn