zoukankan      html  css  js  c++  java
  • Flutter 在 Android 中实现微信支付

    Flutter Android 中实现微信支付 sy_flutter_wechat

    Android 微信支付注意事项

    说明:微信支付没法直接连接调试工具测试,如果直接连接会返回-1,所有这个时候我们重 新用我们以前的签名文件生成签名,然后发到手机测试。
    注意:
    1、微信开放平台必须配置 应用包名 和 应用签名

    2、android 应用包名称必须和微信开放平台配置的一样 3、微信开放平台配置应用签名的时候使用的 keystore 文件必须和正式打包的 keystore 签名 文件一致。
    4、代码中配置的 Appid 必须和开放平台一致
    5、生成预支付信息的服务器 API 接口得提前准备好
    6、android 必须正式打包后才能进行微信支付

    import 'dart:convert';
    import 'package:flutter/material.dart';
    import 'package:sy_flutter_wechat/sy_flutter_wechat.dart';
    import 'package:dio/dio.dart';
    void main() => runApp(MyApp());
    class MyApp extends StatelessWidget {
    // This widget is the root of your application. @override
    Widget build(BuildContext context) {
    return MaterialApp( title: 'Flutter Demo', theme: ThemeData(
    // This is the theme of your application.
    //
    // Try running your application with "flutter run". You'll see
    the
    try
    invoke
    // "hot reload" (press "r" in the console where you ran "flutter run",
    // or simply save your changes to "hot reload" in a Flutter IDE).
    // Notice that the counter didn't reset back to zero; the application
    // is not restarted.
    primarySwatch: Colors.blue, ),
    home: HomePage(), );
    } }
    class HomePage extends StatefulWidget {
    HomePage({Key key}) : super(key: key);
    _HomePageState createState() => _HomePageState(); }
    class _HomePageState extends State<HomePage> {
    @override
    void initState() {
    super.initState();
    _register();
    }
    _register() async {
    bool result = await SyFlutterWechat.register('wx5881fa2638a2ca60'); print(result);
    }
    _weixinPay() async{
    var apiUrl='http://agent.itying.com/wxpay/'; var myPayInfo =await Dio().get(apiUrl);
    // application has a blue toolbar. Then, without quitting the app,
    // changing the primarySwatch below to Colors.green and then

    Map myInfo =json.decode(myPayInfo.data); print(myInfo);
    var payInfo={ "appid":myInfo["appid"].toString(), "partnerid":myInfo["partnerid"].toString(), "prepayid":myInfo["prepayid"].toString(), "package":myInfo["package"].toString(), "noncestr":myInfo["noncestr"].toString(), "timestamp":myInfo["timestamp"].toString(), "sign":myInfo["sign"].toString(),
    };
    SyPayResult payResult = await SyFlutterWechat.pay(
    SyPayInfo.fromJson(payInfo)); print(payResult);
    }
    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: Text("微信"), ),
    body: Center(
    child: Column(
    mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
    RaisedButton(
    child: Text('分享文字'), onPressed: () async {
    bool res = await SyFlutterWechat.shareText('hello
    shareType: SyShareType.session); print('分享文字:' + res.toString());
    }, ),
    RaisedButton(
    child: Text('分享图片'), onPressed: () async {
    bool res = await SyFlutterWechat.shareImage( 'https://avatars0.githubusercontent.com/u/10024776',
    world',


    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: _weixinPay,
    ), ],
    ), ),
    ); }
    }
  • 相关阅读:
    VMware克隆虚拟机,克隆机网卡启动不了解决方案
    实现列表双击可编辑,异步更新;实现删除的即时移除;
    HTTP请求之:PHP函数header常用功能
    MySQL Innodb的两种表空间方式
    MySQL表分区技术
    [java]实体类(VO,DO,DTO,PO)的划分
    [java]框架中为什么用到反射?
    [java]springboot集成mybatis
    [java]servlet乱码问题解决
    [sql]mysql部署
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12761345.html
Copyright © 2011-2022 走看看