wht_sande_pay 0.1.0 copy "wht_sande_pay: ^0.1.0" to clipboard
wht_sande_pay: ^0.1.0 copied to clipboard

A new Flutter plugin.

example/lib/main.dart

import 'dart:math';

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

import 'package:flutter/services.dart';
import 'package:wht_sande_pay/sdp_payment_bean.dart';
import 'package:wht_sande_pay/wechat_kit.dart';
import 'package:wht_sande_pay/wht_sande_pay.dart';
import 'package:wht_sande_pay_example/http_util.dart';



void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


  /// 微信支付
  late final StreamSubscription<BaseResp> _auth;

  @override
  void initState()  {
    super.initState();

    _auth = Wechat.instance.respStream().listen(_listenPay);

    Wechat.instance.registerApp(
        appId: "wx24932e45899137eb",
        universalLink: "https://mmall.mixienet.com.cn/apple-app-site-association/");

    // initPlatformState();

  }

  /// 微信支付回调
  void _listenPay(BaseResp resp) {
    /// errorCode:
    /// -1: 包名或者证书不一致(无法拉起微信app)
    /// 0: 支付成功
    /// -2: 支付失败(无效订单、订单重复支付、订单过期失效和用户取消支付)
    print('支付: $resp');


  }

  // sign_type
  // order_amt
  // product_code
  // goods_name
  // mer_order_no
  // jump_scheme
  // create_ip

  void reqestSignInfo({
    required String signType,
    required String orderAmt,
    required String merOrderNo,
    required String createIp,
    required String productCode
  }){

    ///http://121.5.198.218:8888/trading/results
    ///
    MyHttpUtil().post("https://notify.qidiangouwu.com/sande/api/sign",data: {
      "sign_type" : signType,
      "order_amt" : orderAmt,
      "mer_order_no" :merOrderNo,
      "new_order_no" :  "",
      "create_ip" : createIp,
      "goodsName" : "测试商品",
      "code" : 100001
    }).then((value) {
      SDPPaymentBean bean =  SDPPaymentBean(productCode:productCode, orderAmt: "0.01", goodsName: "测试商品名称");
      Wechat.instance.generalPayment(bean: bean,parameter: value.data);
    });

  }



  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {

  }

  _randomBit(int len) {
    String scopeF = '123456789'; //首位
    String scopeC = '0123456789'; //中间
    String result = '';
    for (int i = 0; i < len; i++) {
      if (i == 0) {
        result = scopeF[Random().nextInt(scopeF.length)];
      } else {
        result = result + scopeC[Random().nextInt(scopeC.length)];
      }
    }  return result;
  }




  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Container(
            child: Center(
              child: Column(
                children: [
                  /// 微信02010005 支付宝02020004  银联02030001  链接02000002 杉德宝02040001
                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Container(
                      width: 150,
                      height: 50,
                      color: Colors.deepOrange,
                      child: InkWell(
                          onTap: (){
                            // FlutterPay.payment(bean: SDPPaymentBean(productCode: "02010005", orderAmt: "0.01", goodsName: "测试商品名称"));
                            reqestSignInfo(productCode: "02010005",signType: "MD5", orderAmt: "0.01", merOrderNo: _randomBit(20), createIp: "192_168_0_1");
                          },
                          child: const Center(child: Text('微信支付',style: TextStyle(color: Colors.white),))),
                    ),
                  ),

                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Container(
                      width: 150,
                      height: 50,
                      color: Colors.deepOrange,
                      child: InkWell(
                          onTap: (){
                            // FlutterPay.payment(bean: SDPPaymentBean(productCode: "02020004", orderAmt: "0.02", goodsName: "测试支付宝商品名称"));
                            reqestSignInfo(productCode: "02020004",signType: "MD5", orderAmt: "0.01", merOrderNo: _randomBit(19), createIp: "192_168_0_1");

                          },
                          child: const Center(child: Text('支付宝支付',style: TextStyle(color: Colors.white),))),
                    ),
                  ),

                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Container(
                      width: 150,
                      height: 50,
                      color: Colors.deepOrange,
                      child: InkWell(
                          onTap: (){
                            // FlutterPay.payment(bean: SDPPaymentBean(productCode: "02030001", orderAmt: "0.02", goodsName: "银联支付商品名称"));
                            reqestSignInfo(productCode: "02030001",signType: "MD5", orderAmt: "0.01", merOrderNo: _randomBit(19), createIp: "192_168_0_1");

                          },
                          child: const Center(child: Text('银联支付',style: TextStyle(color: Colors.white),))),
                    ),
                  ),

                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Container(
                      width: 150,
                      height: 50,
                      color: Colors.deepOrange,
                      child: InkWell(
                          onTap: (){
                            // FlutterPay.payment(bean: SDPPaymentBean(productCode: "02000002", orderAmt: "0.02", goodsName: "测试链接好友商品名称"));
                            reqestSignInfo(productCode: "02000002",signType: "MD5", orderAmt: "0.01", merOrderNo: _randomBit(19), createIp: "192_168_0_1");

                          },
                          child: const Center(child: Text('链接好友支付',style: TextStyle(color: Colors.white),))),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
120
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

A new Flutter plugin.

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

convert, crypto, flutter, json_annotation

More

Packages that depend on wht_sande_pay

Packages that implement wht_sande_pay