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,
), ],
), ),
); }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM