Flutter implements WeChat payment in Android

Flutter Android implements WeChat payment sy_flutter_wechat

 

Notes on Android WeChat Payment

Note: WeChat Pay cannot be directly connected to the debugging tool to test. If it is directly connected, it will return -1. At this time, we will use our previous signature file to generate a signature and send it to the mobile phone for testing.
Note:
1. WeChat open platform must be configured with application package name and application signature

2. The name of the Android application package must be the same as the WeChat open platform configuration 3. The keystore file used when configuring the application signature on the WeChat open platform must be the same as the officially packaged keystore signature file.
4. The Appid configured in the code must be consistent with the open platform
5. The server API interface that generates prepayment information must be prepared in advance
6. Android must be officially packaged before WeChat payment

 

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 (' Share picture: '+ res.toString ());
},),
RaisedButton (
child: Text (' Share page '), onPressed: () async {
bool res = await SyFlutterWechat.shareWebPage ('Title',
'Description',
'https://avatars0.githubusercontent.com/u/10024776', 'http://www.example.com',
shareType: SyShareType.session); print ( 'Share page:' + res.toString ());
},),
RaisedButton (
child: Text ('payment'), onPressed: _weixinPay,
),],
),),
);}
}

Guess you like

Origin www.cnblogs.com/zhaofeis/p/12761345.html
Recommended