wftpay 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 40

wftpay #

A new flutter plugin project.

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.


  • [ ] 优能配置 使用优能提供的参数(appId、mch_id和key),无法成功吊起支付,提示支付类型未开通;使用威富通提供的参数,可以支付一次,再一次支付必须重装微信

  • [ ] 回调未测试

使用前准备 #






商户在微信开放平台申请开发APP应用后,微信开放平台会生成APP的唯一标识APPID。在Xcode中打开项目,设置项目属性中的URL Schemes为您的APPID





使用 #

// 获取当前设备版本号(dome原方法)
result = await Wftpay.platformVersion;

// 以下两个函数
// 返回0为支付成功,其它为失败
// -1 原因:支付错误,可能的原因:签名错误、未注册APPID、项目设置APPID不正确、注册的APPID与设置的不匹配、其他异常等
// -2 原因 用户取消,无需处理。发生场景:用户不支付了,点击取消,返回APP(ios没有这个判断)

// 支付
result = await Wftpay.wxPay({
    'appId': '', // 微信应用appId
    'token_id': '', // 通过请求服务器统一下单接口返回的参数,在小程序和H5中是一个Object,其中包含sign,nonce_str等参数,而在app中只需要用到其中的token_id即可
    'amount': '1', // ios需要此参数,只用于扫码支付和付款码支付类型时客户端显示金额。不会参与交易计算,具体的交易金额以下单时候传入的金额为准。
// 支付测试,以下参数由威富通提供
// 与支付不同的是,测试支付不需要通过请求服务器统一下单接口返回的参数,而是在app中自己调用微信统一下单接口拿取数据
// 因此只提供测试使用,真实场景一定不能用这种方法,有泄漏密钥的风险,记得删除
result = await Wftpay.wxPayTest(
    appId: 'wx2a5538052969956e', // 微信应用appId
    mch_id: '755437000006', // 商户号
    key: '7daa4babae15ae17eee90c9e', // 密钥

ios开发遇坑 #

1.如果遇到plist的报错,如下,在xcode-file-workspace setting中将build system设置为Legacy Build System(第二个)


Multiple commands produce '/Users/mac/Library/Developer/Xcode/DerivedData/Runner-ahdzorlajnxaikghzbfwnbmlhtci/Build/Products/Debug-iphonesimulator/wftpay/Info.plist'

Multiple commands produce '/Users/mac/Library/Developer/Xcode/DerivedData/Runner-ahdzorlajnxaikghzbfwnbmlhtci/Build/Products/Debug-iphonesimulator/wftpay/Info-8.0+.plist'

参考文档 #









0.0.1 #

  • TODO: Describe initial release.


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

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
      home: MyHomePage(),

class MyHomePage extends StatefulWidget {
  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  String _wxPayRes = 'Unknown';

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> _getVersion() async {
    String result;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      result = await Wftpay.platformVersion;
    } on PlatformException {
      result = 'Failed to get version';

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _wxPayRes = result;

  Future<void> _wxPay() async {
    int result;
    try {
      result = await Wftpay.wxPay({
        'appId': '',
        'token_id': '',
        'amount': '1', // ios需要此参数,只用于扫码支付和付款码支付类型时客户端显示金额。不会参与交易计算,具体的交易金额以下单时候传入的金额为准。
    } on PlatformException {
      result = -1;

    if (!mounted) return;

    setState(() {
      _wxPayRes = result.toString();

  Future<void> _wxPayTest() async {
    int result;
    try {
      // 威富通测试
      // result = await Wftpay.wxPayTest(
      //   appId: 'wx2a5538052969956e',
      //   mch_id: '755437000006',
      //   key: '7daa4babae15ae17eee90c9e',
      // );

      // 优能测试(注:保密信息)
      result = await Wftpay.wxPayTest(
        appId: 'wx2ed812e4b0ff3497',
        mch_id: '159550002527',
        key: '2c5e291205e9980244a2ec34c69eff95',
    } on PlatformException {
      result = -1;

    if (!mounted) return;

    setState(() {
      _wxPayRes = result.toString();

  Widget build(BuildContext context) {
    return new Material(
      child: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            new RaisedButton(
              child: new Text('version'),
              onPressed: _getVersion,
            new RaisedButton(
              child: new Text('pay'),
              onPressed: _wxPay,
            new RaisedButton(
              child: new Text('payTest'),
              onPressed: _wxPayTest,
            new Text(_wxPayRes),

Use this package as a library

1. Depend on it

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

  wftpay: ^0.0.1

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:wftpay/wftpay.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:wftpay/wftpay.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:wftpay/wftpay.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:wftpay/wftpay.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:wftpay/wftpay.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [wftpay] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

6 out of 6 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/wftpay.dart. (-0.50 points)

Analysis of lib/wftpay.dart reported 1 hint:

line 19 col 49: Name non-constant identifiers using lowerCamelCase.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field was unreachable.

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.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies