| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import '../styles/totast.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../model/ProductInfo.dart';
- import '../redux/UserRedux.dart';
- import '../model/UserInfo.dart';
- import 'package:fluwx/fluwx.dart' as fluwx;
- import 'package:get_ip/get_ip.dart';
- import 'package:dio/dio.dart';
- import 'dart:convert';
- import '../widget/Dialog.dart';
- class ChoosePay extends StatefulWidget {
- ChoosePay(this.type, this.chooseProduct);
- int type;
- ProductInfo chooseProduct;
- @override
- _ChoosePayState createState() => _ChoosePayState();
- }
- class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
- String chooseKey = 'wxpay';
- Future<void> getUserInfo() async {
- Result res = await HttpManager.get('userInfo/getUserInfo');
- if (res.success) {
- print(res.data);
- StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
- } else {}
- }
- @override
- void initState() {
- super.initState();
- fluwx.register(appId: "wx62f8a9c1d3d70245");
- Future.delayed(Duration.zero, () => getUserInfo());
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('选择支付方式'),
- centerTitle: true,
- ),
- body: Container(
- color: Color(0xFF2E3049),
- child: Column(
- children: <Widget>[
- Container(
- height: 142,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Text(
- '需支付',
- style: TextStyle(color: Theme.of(context).primaryColor, fontSize: 12),
- ),
- Container(
- width: 10,
- ),
- Text('¥${widget.chooseProduct.money}', style: TextStyle(color: Theme.of(context).primaryColor, fontSize: 38))
- ],
- ),
- ),
- // PayContent('支付宝', '支持有支付宝,网银的用户使用', 'images/icon_zhifubao.png', 'alipay', chooseKey, () {
- // setState(() {
- // chooseKey = 'alipay';
- // });
- // }),
- PayContent('微信支付', '使用微信支付,方便快捷', 'images/icon_weixin.png', 'wxpay', chooseKey, () {
- setState(() {
- chooseKey = 'wxpay';
- });
- })
- ],
- ),
- ),
- floatingActionButton: Container(
- width: double.infinity,
- padding: EdgeInsets.symmetric(horizontal: 15),
- height: 48,
- child: FlatButton(
- color: Theme.of(context).primaryColor,
- textColor: Colors.white,
- child: Text('立即支付'),
- onPressed: () async {
- // return;
- String ipAddress = await GetIp.ipAddress;
- print(ipAddress);
- final Result res = await HttpManager.get('lyf/appUnifiedOrder', data: {
- 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
- // 'typeFlag': widget.type,
- 'ip': ipAddress,
- 'productId': widget.chooseProduct.id
- });
- print(StoreProvider.of<AppState>(context).state.userInfo.id);
- if (res.success) {
- fluwx.launchMiniProgram(username: "gh_a6a98cd9b3cd", path: "page/component/confirm/index?data=" + res.data["data"]).then((res) {
- print(res);
- });
- MyDialog.showDialog(context, '已经成功调起微信支付', submitText: '支付完成', isCancel: true, onsubmit: () async {
- final Result res2 = await HttpManager.get('wxpayTemp/getWxpayTemp', data: {'id': res.data["id"]});
- if (res2.success && res2.data != new Map()) {
- if (res2.data['resultCode'] == 'NOT_PAY') {
- Toast.show(context, '支付取消', 1500, 'info');
- } else {
- Toast.show(context, '购买成功', 1500, 'success');
- getUserInfo();
- Navigator.of(context).pop();
- }
- }
- });
- }
- // String str= 'eyJhbW91bnQiOiIxIiwiYX
- // String str= 'eyJhbW91bnQiOiIxIiwiYXR0YWNoIjoie1widG90YWxcIjoxLFwicHJvZHVjdElkXCI6XCIxXCIsXCJ1c2VySWRcIjpcIjg0NzA1XCIsXCJjYXNoXCI6MTB9IiwiYm9keSI6IjHpl6jnpagiLCJtY2hfaWQiOiIxMDAwMDAwODM1NDEiLCJub25jZV9zdHIiOiI1ZmM3NWVlZmY0MjA0MGEwYmEwMWQwZDE2NGJhYmU2YyIsIm5vdGlmeV91cmwiOiJodHRwOi8vMTIzLjU4LjI0MC4xMzg6OTAwMC8iLCJvdXRfdHJhZGVfbm8iOiIxNTY0OTkzMjYwNDc0NjQxNTcyNyIsInBheW1lbnRfdHlwZSI6InRyYWRlLndlaXhpbi5hcHAiLCJyZXR1cm5fdXJsIjoiaHR0cDovLzEyMy41OC4yNDAuMTM4OjkwMDAvbHlmL25vdGlmeSIsInNpZ24iOiIxYjg0NWE4ZjNmYWI0OTA1NTViYWE5MGZkYzFkODc1MyIsInNpZ25fdHlwZSI6Ik1ENSIsInNwYmlsbF9jcmVhdGVfaXAiOiIxMTkuMTM3LjU1LjE4OSJ9'; fluwx.launchMiniProgram(username: "gh_a6a98cd9b3cd",path:"page/component/confirm/index?data="+str);
- // fluwx.launchMiniProgram(username: "gh_a6a98cd9b3cd",path:"page/component/confirm/index?data="+str);
- // Toast.show(context, '加载中', -1, 'loading');
- // final Result res = await HttpManager.post('productInfo/buy', data: {
- // 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
- // 'typeFlag': widget.type,
- // 'money': widget.chooseProduct.money,
- // 'id': widget.chooseProduct.id
- // });
- // Toast.hide();
- // if (res.success) {
- // Toast.show(context, '购买成功', 1500, 'success');
- // getUserInfo();
- // Navigator.of(context).pop();
- // } else {
- // Toast.show(context, res.error, 1500, 'info');
- // }
- },
- ),
- ),
- floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
- );
- }
- }
- typedef void OnTapMenu();
- class PayContent extends StatelessWidget {
- PayContent(this.name, this.subName, this.image, this.keyVal, this.chooseKey, this.tapMenu);
- String name;
- String subName;
- String image;
- String keyVal;
- String chooseKey;
- OnTapMenu tapMenu;
- List<String> chooseIcon = ['images/icon_weixuanzhong.png', 'images/icon_xuanzhong2.png'];
- @override
- Widget build(BuildContext context) {
- return Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: tapMenu,
- child: Container(
- height: 86,
- padding: EdgeInsets.fromLTRB(30, 18, 30, 18),
- decoration: BoxDecoration(
- border: Border(
- top: BorderSide(width: 1, color: Color(0xFF25273C)),
- )),
- child: Row(
- children: <Widget>[
- Image.asset(image),
- Container(
- width: 10,
- ),
- Expanded(
- flex: 1,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- name,
- style: TextStyle(color: Colors.white, fontSize: 14),
- ),
- Container(
- height: 6,
- ),
- Text(
- subName,
- style: TextStyle(color: Color(0xFF727785), fontSize: 13),
- )
- ],
- ),
- ),
- Image.asset(chooseIcon[keyVal == chooseKey ? 1 : 0])
- ],
- ),
- )));
- }
- }
|