Flutter下能使用的微信SDK及支付宝SDK

今天试用了flutter能实战的微信SDK(包括分享和支付),该作者还提供了一个支付宝的SDK,分享出来,供参考:

写在一起的demo,iOS上运行效果

Flutter下能使用的微信SDK及支付宝SDK

微信SDK

包括分享、支付等

项目地址:

https://github.com/lishuhao/sy_flutter_wechat

说明

分享图片及链接暂时仅支持 网络图片 ,
iOS分享网络图片如果不是 HTTPS 的话可能会失败,因为iOS ATS问题。
微信分享返回的结果仅代表调用微信分享sdk是否成功,不代表用户确实分享出去了,

试例代码

import 'dart:convert';

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    _register();
  }

  _register() async {
    bool result = await SyFlutterWechat.register('wxf9909bde17439ac2');
    print(result);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new ListView(
          padding: EdgeInsets.all(8.0),
          children: <Widget>[
            RaisedButton(
              child: Text('分享文字'),
              onPressed: () async {
                bool res = await SyFlutterWechat.shareText('hello world',
                    shareType: SyShareType.session);
                print('分享文字:' + res.toString());
              },
            ),
            RaisedButton(
              child: Text('分享图片'),
              onPressed: () async {
                bool res = await SyFlutterWechat.shareImage(
                    'https://avatars0.githubusercontent.com/u/10024776',
                    shareType: SyShareType.timeline);
                print('分享图片:' + res.toString());
              },
            ),
            RaisedButton(
              child: Text('分享网页'),
              onPressed: () async {
                bool res = await SyFlutterWechat.shareWebPage(
                    '标题',
                    '描述',
                    'https://avatars0.githubusercontent.com/u/10024776',
                    'http://www.example.com',
                    shareType: SyShareType.session);
                print('分享网页:' + res.toString());
              },
            ),
            RaisedButton(
              child: Text('支付'),
              onPressed: () async {
                String payInfo =
                    '{"appid":"wxf9909bde17439ac2","partnerid":"1518469211","prepayid":"wx120649521695951d501636f91748325073","package":"Sign=WXPay","noncestr":"1541976592","timestamp":"1541976592","sign":"E760C99A1A981B9A7D8F17B08EF60FCC"}';
                SyPayResult payResult = await SyFlutterWechat.pay(
                    SyPayInfo.fromJson(json.decode(payInfo)));
                print(payResult);
              },
            ),
          ],
        ),
      ),
    );
  }
}

支付宝SDK

首先在pubspec.ymal 添加依赖

项目地址:

https://github.com/lishuhao/sy_flutter_alipay

demo

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('sy_flutter_alipay example'),
        ),
        body: new Center(
          child: RaisedButton(
              child: Text('支付'),
              onPressed: () async {
                const payInfo ="从服务端获取的支付参数";
                var result = await SyFlutterAlipay.pay(
                    payInfo,
                    urlScheme: '你的ios urlScheme', //前面配置的urlScheme
                    isSandbox: true //是否是沙箱环境,只对android有效
                );
                print(result);
              }),
        ),
      ),
    );
  }
}

相关推荐