App扫码登录

4 篇文章 0 订阅

1:原理如下

	点击扫码登录,后端生成一个随机数和该随机数生成的二维码;app扫码后得到这个随机数,把这个随机数和用户id请求都后端,后端把这个随机数和用户id保存到一张临时数据表;pc端jq轮询携带随机数请求后端这个数据表,如果发现则登录。

2:部分代码

//循环请求数据
for (var i = 0; i < 30; i++) {
         (function (j) {
             setTimeout(function() {
                 console.log(j);
                 $.ajax({
                     type:"get",
                     url:"/store/getResCode",
                     data:{
                         'login_code':data.data.re_val,
                         _token:'{{ csrf_token() }}'
                     },
                     dataType:"json",
                     success:function(data){
                         if(data){
                             window.location.href="/store";
                             return false;
                         }
                     }
                 });
             }, 2000 * j);
         })(i);
     }

图片Base64

    /**
     * 登录二维码
     * @return array
     */
    public function phpQrCodes()
    {
        include app_path().'/Lib/phpqrcode.php';
        $errorCorrectionLevel = 'L';//容错级别
        $matrixPointSize = 10;//生成图片大小
        //二维码
         $PaymentPayFlow=new PaymentPayFlow;
        //创建唯一token值
        $order_id=$this->genId();
        $re_val=$PaymentPayFlow->generatePayFlowNumber($order_id, 'qrlogin', 'phpQrCodes', time());
        $ewm = QRcode::pngToBase64($re_val,false,$errorCorrectionLevel,$matrixPointSize,0);
        $info = [
            're_val' => $re_val,
            'ewm'    => $ewm,
        ];
        return $this->format('1', "请求成功", $info);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的Android登录的示例代码,使用了Google提供的ZXing码库: 1. 在项目的build.gradle文件中添加依赖: ``` dependencies { implementation 'com.google.zxing:core:3.3.3' implementation 'com.journeyapps:zxing-android-embedded:3.5.0' } ``` 2. 在需要登录的Activity中添加码逻辑: ``` public class LoginActivity extends AppCompatActivity { private Button mScanButton; private TextView mResultTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mScanButton = findViewById(R.id.scan_button); mResultTextView = findViewById(R.id.result_textview); mScanButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 启动码界面 IntentIntegrator integrator = new IntentIntegrator(LoginActivity.this); integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE); integrator.setPrompt("请将二维码置于框内"); integrator.setCameraId(0); integrator.setBeepEnabled(false); integrator.setBarcodeImageEnabled(false); integrator.initiateScan(); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if (result != null) { if (result.getContents() != null) { // 获取码结果 String scanResult = result.getContents(); // 将码结果显示在TextView上 mResultTextView.setText(scanResult); } else { Toast.makeText(this, "码已取消", Toast.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode, resultCode, data); } } } ``` 3. 在布局文件中添加Button和TextView: ``` <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/scan_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" android:layout_centerInParent="true"/> <TextView android:id="@+id/result_textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/scan_button" android:layout_centerHorizontal="true"/> </RelativeLayout> ``` 以上代码仅为示例,实际应用中还需要根据具体业务逻辑进行修改。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值