fake_alipay 0.2.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

fake_alipay #

Build Status Codecov GitHub Tag Pub Package License

flutter版支付宝SDK

fake 系列 libraries #

dart/flutter 私服 #

docs #

android #

# 不需要做任何额外接入工作
# 混淆已打入 Library,随 Library 引用,自动添加到 apk 打包混淆

ios #

在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id

URL Types
alipay: identifier=alipay schemes=${your app scheme name} # schemes 不能为纯数字,推荐:alipay${appId}
iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>alipay</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

flutter #

  • snapshot
dependencies:
  fake_alipay:
    git:
      url: https://github.com/v7lin/fake_alipay.git
  • release
dependencies:
  fake_alipay: ^${latestTag}
  • example

示例

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.2.3 - 2019.9.20 #

  • 删除RSA2对密钥长度的检查

0.2.2 - 2019.7.12 #

  • 简化

0.2.1 - 2019.6.21 #

  • 修正线程安全

0.2.0 - 2019.5.24 #

  • 优化
  • 自动化发布

0.1.1 - 2019.3.20 #

  • BUG 修复

0.1.0 - 2019.3.18 #

  • 规范 library 代码

0.0.1 - 2019.3.1 #

  • android/ios alipay

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:fake_alipay/fake_alipay.dart';

void main() {
  runZoned(() {
    runApp(MyApp());
  }, onError: (Object error, StackTrace stack) {
    print(error);
    print(stack);
  });

  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

/// pkcs1 -> '-----BEGIN RSA PRIVATE KEY-----\n${支付宝RSA签名工具生产的私钥}\n-----END RSA PRIVATE KEY-----'
/// pkcs8 -> '-----BEGIN PRIVATE KEY-----\n${支付宝RSA签名工具生产的私钥}\n-----END PRIVATE KEY-----'
class _HomeState extends State<Home> {
  static const bool _ALIPAY_USE_RSA2 = true;
  static const String _ALIPAY_APPID = 'your alipay appId'; // 支付/登录
  static const String _ALIPAY_PID = 'your alipay pid'; // 登录
  static const String _ALIPAY_TARGETID = 'your alipay targetId'; // 登录
  static const String _ALIPAY_PRIVATEKEY =
      'your alipay rsa private key(pkcs1/pkcs8)'; // 支付/登录

  Alipay _alipay = Alipay();

  StreamSubscription<AlipayResp> _pay;
  StreamSubscription<AlipayResp> _auth;

  @override
  void initState() {
    super.initState();
    _pay = _alipay.payResp().listen(_listenPay);
    _auth = _alipay.authResp().listen(_listenAuth);
  }

  void _listenPay(AlipayResp resp) {
    String content = 'pay: ${resp.resultStatus} - ${resp.result}';
    _showTips('支付', content);
  }

  void _listenAuth(AlipayResp resp) {
    String content = 'pay: ${resp.resultStatus} - ${resp.result}';
    _showTips('授权登录', content);
  }

  @override
  void dispose() {
    if (_pay != null) {
      _pay.cancel();
    }
    if (_auth != null) {
      _auth.cancel();
    }
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Fake Alipay Demo'),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: const Text('环境检查'),
            onTap: () async {
              String content = 'alipay: ${await _alipay.isAlipayInstalled()}';
              _showTips('环境检查', content);
            },
          ),
          ListTile(
            title: const Text('支付'),
            onTap: () {
              Map<String, String> bizContent = <String, String>{
                'timeout_express': '30m',
                'product_code': 'QUICK_MSECURITY_PAY',
                'total_amount': '0.01',
                'subject': '1',
                'body': '我是测试数据',
                'out_trade_no': '123456789',
              };
              Map<String, String> orderInfo = <String, String>{
                'app_id': _ALIPAY_APPID,
                'biz_content': json.encode(bizContent),
                'charset': 'utf-8',
                'method': 'alipay.trade.app.pay',
                'timestamp': '2016-07-29 16:55:53',
                'version': '1.0',
              };
              _alipay.payOrderMap(
                orderInfo: orderInfo,
                signType: _ALIPAY_USE_RSA2
                    ? Alipay.SIGNTYPE_RSA2
                    : Alipay.SIGNTYPE_RSA,
                privateKey: _ALIPAY_PRIVATEKEY,
              );
            },
          ),
          ListTile(
            title: const Text('授权'),
            onTap: () {
              _alipay.auth(
                appId: _ALIPAY_APPID,
                pid: _ALIPAY_PID,
                targetId: _ALIPAY_TARGETID,
                privateKey: _ALIPAY_PRIVATEKEY,
              );
            },
          ),
        ],
      ),
    );
  }

  void _showTips(String title, String content) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text(title),
          content: Text(content),
        );
      },
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fake_alipay: ^0.2.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fake_alipay/fake_alipay.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
73
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Apr 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
fake_crypto >=0.1.0 <1.0.0 0.1.0
flutter 0.0.0
jaguar_serializer >=2.2.12 <3.0.0 2.2.12
meta >=1.1.6 <2.0.0 1.1.8
Transitive dependencies
asn1lib 0.6.4
collection 1.14.11 1.14.12
pointycastle 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner any
flutter_test
jaguar_serializer_cli any
pedantic >=1.4.0 <3.0.0