alipay_me 1.0.0
alipay_me: ^1.0.0

Flutter Android iOS

Alipay plug-in. Support payment and authorized login. Support Android and iOS. Android supports local computational signatures.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';

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

import 'sign.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Page(),
    );
  }


}

class Page extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _PageState();
  }
}

class _PageState extends State<Page> {
  String msg = "";
  bool _isSandbox = false;
  String version;

  @override
  void initState() {
    super.initState();
    AlipayMe.getVersion().then((v) {
      setState(() {
        version = v;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: const Text('支付宝插件示例'),
      ),
      body: Padding(padding: const EdgeInsets.all(16.0), child: ListView(
        primary: true,
        children: <Widget>[
          Text("开发包版本号:${version ?? ""}"),
          SizedBox(height: 8.0),
          Row(
            children: <Widget>[
              Checkbox(value: _isSandbox, onChanged: (v) {
                setState(() {
                  _isSandbox = v;
                });
              }),
              Text("沙盒模式")
            ],
          ),
          SizedBox(height: 32.0),
          OutlineButton(child: Text("支付"), onPressed: () {
            doPay(context);
          }),
          OutlineButton(child: Text("授权登录"), onPressed: () {
            doOauth(context);
          }),
          SizedBox(height: 32.0),
          OutlineButton(child: Text("测试Sign"), onPressed: () {
            testSign();
          }),
          SizedBox(height: 32.0),
          Text(msg ?? "", style: TextStyle(fontSize: 10.0, color: Colors.blue)),
        ],
      )),
    );
  }

  doPay(BuildContext context) async {
    showDialog<void>(context: context, builder: (context) {
      TextEditingController edtPayInfo = new TextEditingController();
      return AlertDialog(
        title: Text("支付宝付款"),
        content: Container(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text("请输入服务器返回的payInfo:"),
              TextField(
                controller: edtPayInfo,
                maxLines: 2,
              )
            ],
          ),
        ),
        actions: <Widget>[
          FlatButton(
            child: Text("取消"),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
          FlatButton(
            child: Text("确定"),
            onPressed: () {
              Navigator.pop(context);
              doPayExec(edtPayInfo.text);
            },
          )
        ],
      );
    });
  }

  doPayExec(String apyInfo) async {
    print("apyInfo: $apyInfo");
    await initAlipay();

    var o = await AlipayMe.pay(apyInfo,
      urlScheme: "alisdkdemo",  // 这里的URL Schemes中输入的alisdkdemo,为测试demo,实际商户的app中要填写独立的scheme
      isSandbox: _isSandbox,
    );
    setState(() {
      msg = "$o";
    });
  }

  doOauth(BuildContext context) async {
    await initAlipay();
    String data;
    if (Platform.isIOS) {
      data = "Server AuthInfo";  // ioS平台只支持服务器返回
    }
    var o = await AlipayMe.auth(
      urlScheme: "alisdkdemo", // 这里的URL Schemes中输入的alisdkdemo,为测试demo,实际商户的app中要填写独立的scheme
      isSandbox: _isSandbox,
      authInfo: data,
    );
    setState(() {
      msg = "$o";
    });
  }

  initAlipay() async {
    final String tid = "tid_${DateTime.now().millisecondsSinceEpoch}";
    await AlipayMe.init(
        appId: "2019010362782013",
        pid: "2088012716890635",
        rsa2Private: RSAPrivate,
        targetId: tid
    );
  }

  void testSign() async {
    Map<String, String> map = new Map<String, String>();
    map["appId"] = "2013081700024223";
    map["pid"] = "2088102123816631";
    map["apiname"] = "com.alipay.account.auth";
    map["app_name"] = "mc";
    map["product_id"] = "APP_FAST_LOGIN";
    map["auth_type"] = "AUTHACCOUNT";
    map["test"] = "中文fdsafdsafdas";

    Sign.getSignFormMap(map, RSAPrivate, true).then((v) {
      setState(() {
        msg = v;
      });
      print(v);
    });
  }

  final String RSAPrivate = '''
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC1GnINzLscYTX6
LRMXMDTbuLSBtzxE69s2Acv2WdbKi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ABKfaR0hVlu7wX53cOxNDNtsApqLnN8CZx6VDrd0G82bHIkwazpTAw0LF6KJ
SYMt/UuZlfaORlgPWJMcQvLEx/OAzKAnkFKxRYwRJUD+hmvCByxwGrfc2QUCgYB/
tCUtd3k4rTlgkob711SrvvRKdG6GaPCNfYYgHdFwzD1FS5GOZCnX6WPKQD9OFr0T
NL/SZoQVRyr5GiLe/ZQl7/j+atMW0IG4z4oTKYdfJMjPO4+cWZ6KkXN8UZD53kLB
Y93uvfuqRw+H0tXFb9p+SCE0RT9SsbRok9wvwnUpdQKBgQCld532s35rJi5QF8Oc
CLdtkLoW72sRuzXWgs3VKw9sBpG/lKI5IlQXKR1e2HWaKKkD/ot+3cI3c6HOJPqh
zACH2P5FLDFLJPxfjA8RG58mnF9LjM3pRn5ZAj92Osls8lCRHIMB4B5NsyOq5oXV
JPmyqVL8mnAJW8X/J6mpiCkivQ==''';

}
1
likes
90
pub points
0%
popularity

Alipay plug-in. Support payment and authorized login. Support Android and iOS. Android supports local computational signatures.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

yangyxd@126.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on alipay_me