当前位置:   article > 正文

autojs编写的支付宝支付模板,带toast弹窗,自定义控件,界面上插入图片,功能非常强大和完善值得学习_autojs自动化识别支付金额

autojs自动化识别支付金额

说明

本文提供的代码仅供参考。不建议用于生产环境。
可能有些地方在最新版本的Auto.js上面需要做修改,才能运行。

Auto.js简介

Auto.js是利用安卓系统的“辅助功能”实现类似于按键精灵一样,可以通过代码模拟一系列界面动作的辅助工作。
与“按键精灵”不同的是,它的模拟动作并不是简单的使用在界面定坐标点来实现,而是类似与win一般,找窗口句柄来实现的。

Auto.js使用JavaScript作为脚本语言,目前使用Rhino 1.7.7.2作为脚本引擎,支持ES5与部分ES6特性。

推荐教程

Auto.js Pro安卓全分辨率免ROOT引流脚本开发视频教程(HD超清1080p)

开发文档

Auto.js Pro开发文档
文档尚在完善中,可能有文档描述和代码实际行为有出入的情况。

为什么要使用Auto.js Pro开发脚本,有什么特点?

吸引我使用Auto.js Pro的原因有很多。最主要的几个原因是:

  • Auto.js Pro能开发免ROOT的安卓脚本
  • Auto.js Pro基于节点操作,能开发全分辨率的脚本,自动适配各种安卓机型
  • Auto.js Pro丰富的UI组件,能自定义各种样式的安卓界面
  • Auto.js Pro使用的javascript的语法比较优雅,代码可读性强
  • Auto.js Pro的命令库非常的丰富,接口比较多
  • Auto.js Pro脚本文件体积比较小。1000行的代码,打包后的apk文件只有3-5M,还没有广告

示例代码

/*
 * @Version: Auto.Js Pro
 * @LastEditors: 大柒
 * @Date: 2019-04-30 22:27:06
 * @LastEditTime: 2019-05-05 12:25:42
 * @Description: 支付UI界面
 *  此模板是参照爱奇艺支付模板
 *  使用 自定义控件 降低代码重复率
 *  有支付宝支付功能 是我自己本人的接口
 *  有弹窗模板  仿toast弹窗 
 */
 //此代码由飞云脚本圈整理提供(www.feiyunjs.com)
"ui";
//此代码由飞云脚本圈整理提供(www.feiyunjs.com)
importClass("androidx.drawerlayout.widget.DrawerLayout")
importClass(android.view.WindowManager);
importClass(android.view.View);
importClass(android.graphics.Color)
importClass(android.app.AlertDialog)
importClass(java.io.FileOutputStream);
importClass(java.io.File);


importClass(java.lang.Runnable);
importClass(android.animation.ObjectAnimator)
importClass(android.animation.PropertyValuesHolder)
importClass(android.animation.ValueAnimator)
importClass(android.animation.AnimatorSet)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.TranslateAnimation)
importClass(android.animation.ObjectAnimator)
importClass(android.animation.TimeInterpolator)
importClass(android.os.Bundle)
importClass(android.view.Window)

importClass(android.view.animation.AccelerateDecelerateInterpolator)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.AnticipateInterpolator)
importClass(android.view.animation.AnticipateOvershootInterpolator)
importClass(android.view.animation.BounceInterpolator)
importClass(android.view.animation.CycleInterpolator)
importClass(android.view.animation.DecelerateInterpolator)
importClass(android.view.animation.LinearInterpolator)
importClass(android.view.animation.OvershootInterpolator)
importClass(android.view.animation.PathInterpolator)
importClass(android.widget.Button)
importClass(android.widget.ImageView)
importClass(android.widget.TextView)

//用户信息
user = {
    name: "大柒",
    id: "15",
    phone: "18000000000",
    time_off: "2019-05-31",
}

//套餐信息
payName = "黄金VIP套餐"

//IMG图片数据
img_zfb = "http://gdown.baidu.com/img/0/512_512/4bfcfd18afa6dc68ef84b00302344dbd.png";
img_wx = "https://16570095.s21i.faiusr.com/4/ABUIABAEGAAgh9i35gUogKLn1wUwgAQ4gAQ.png";
img_user = "https://16570095.s21i.faiusr.com/2/ABUIABACGAAgu9y35gUo0Mbk_AUw9AM49AM.jpg"

const animation_time = 500//动画时间

//任务栏透明
var window = activity.getWindow();
var decorView = window.getDecorView();
var option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
window.setStatusBarColor(Color.TRANSPARENT);

//确认支付按钮 背景和文字color
pay_bnt = {
    s: { bg: "#e3e3e3", color: "#ffffff" },
    c: { bg: "#f2c186", color: "#6b4128" }
}

var MyColor = "#3d3d3f"//主题色
const log_back = "@drawable/ic_chevron_left_black_48dp"//返回按钮

var v_meal_bg = [];//套餐view信息
var v_pay_radio = [];//支付方式 单选框值
var order = {};
var remind = {};

//订单支付信息
var data = {
    name: user.name,
    id: user.id,
    goods: payName,
    money: "",
    pay: "",
    date: "",
}

//自定义控件 充值套餐
var setMealLayout = (function () {
    util.extend(setMealLayout, ui.Widget);
    function setMealLayout() {
        ui.Widget.call(this);
        this.defineAttr("title", (view, attr, value, defineSetter) => {
            view._title_bg.attr("visibility", "visible");
            view._title_text.setText(value);
        })
        this.defineAttr("month", (view, attr, value, defineSetter) => {
            view._month.setText(value);
        });
        this.defineAttr("money", (view, attr, value, defineSetter) => {
            view._money.setText(value);
        });
        this.defineAttr("subtitle", (view, attr, value, defineSetter) => {
            view._subtitle.attr("visibility", "visible");
            view._subtitle.setText(value);
        });
        this.defineAttr("remind", (view, attr, value, defineSetter) => {
            view._remind_bg.attr("visibility", "visible");
            view._remind.setText(value);
        });
        this.defineAttr("onClick", (view, name, defaultGetter) => {
            return this._onClick;
        }, (view, name, value, defaultSetter) => {
            v_meal_bg[v_meal_bg.length] = view
            this._onClick = value;
        });
    };
    setMealLayout.prototype.render = function () {
        return (
            <frame h="*" w="*" marginRight="10" >
                <card
                    id="_title_bg"
                    w="auto" h="14"
                    cardCornerRadius="5dp"
                    cardBackgroundColor="#3b3b3b"
                    gravity="center"
                    foreground="?selectableItemBackground"
                    visibility="invisible"
                >
                    <text id="_title_text" text="0" margin="5 0 5 0" textSize="10" textStyle="bold" textColor="#dbbb88" />
                </card>
                <vertical id="_bg" h="*" w="*" marginTop="7" bg="#e3e3e3" >
                    <vertical id="_bg_1" w="*" h="*" margin="1" bg="#ffffff" gravity="center_horizontal">
                        <text id="_month" w="auto" text="0个月" marginTop="10" textStyle="bold" textSize="22" />
                        <horizontal w="auto" h="auto" >
                            <text text="¥" textColor="#a37655" />
                            <text id="_money" text="0.00" textColor="#a37655" textSize="32" textStyle="bold" typeface="serif" />
                        </horizontal>
                        <text id="_subtitle" w="auto" text="0" textSize="10" visibility="invisible" />
                        <card id="_remind_bg"
                            w="auto" h="auto"
                            marginTop="5" marginBottom="15"
                            cardCornerRadius="6"
                            cardBackgroundColor="#dcbb86"
                            gravity="center"
                            foreground="?selectableItemBackground"
                            visibility="invisible" >
                            <horizontal margin="2 0 2 0">
                                <img w="10" h="10" margin="5 2 3 0" src="@drawable/ic_thumb_up_black_48dp" tint="#ffffff" />
                                <text id="_remind" text="0" margin="0 0 5 0" textSize="10" textStyle="bold" textColor="#ffffff" />
                            </horizontal>
                        </card>
                    </vertical>
                </vertical>
            </frame>
        );
    };
    setMealLayout.prototype.onViewCreated = function (view) {
        view.on("click", () => {
            if (this._onClick) {
                for (let i = 0; i != v_meal_bg.length; i++) {
                    v_meal_bg[i]._bg.attr("bg", "#e3e3e3");
                    v_meal_bg[i]._bg_1.attr("alpha", "1");
                }
                ui.money.setText(view._money.text())
                ui.money_s.setText("你已选择" + ui.money_name.text() + view._month.text() + "套餐")
                data.money = parseInt(view._month.text())
                view._bg.attr("bg", "#d6bf93");
                view._bg_1.attr("alpha", "0.8");
                pay_money = parseInt(view._month.text())
                eval(this._onClick);
            }
        });
    };
    ui.registerWidget("setMeal-layout", setMealLayout);
    return setMealLayout;
})();

//自定义控件 用户信息标题
var userTitleLayout = (function () {
    util.extend(userTitleLayout, ui.Widget);
    function userTitleLayout() {
        ui.Widget.call(this);
    }
    userTitleLayout.prototype.render = function () {
        return (
            <horizontal h="*" w="*" bg="{{MyColor}}" gravity="center_vertical"  >
                <img marginLeft="10" src="{{img_user}}" h="44" w="44" circle="true" scaleType="fitXY" layout_gravity="center_vertical" />
                <vertical w="*" h="44" marginLeft="10" >
                    <horizontal h="22" gravity="vertical_center">
                        <text id="user_name" text="{{user.name}}" textSize="18" textStyle="bold" textColor="#ffffff" />
                        <card w="auto" h="auto" margin="5 3 0 0" cardCornerRadius="5dp" cardBackgroundColor="#dbbb88"
                            cardElevation="5dp" gravity="center" foreground="?selectableItemBackground">
                            <horizontal margin="5 0 5 0">
                                <text id="user_id" text="ID: {{user.id}}" textColor="{{MyColor}}" textStyle="bold" />
                            </horizontal>
                        </card>
                        <text id="user_phone" text="({{user.phone}} 登录)" h="*" marginTop="1" textSize="16" gravity="center_vertical" textColor="#ffffff" />
                    </horizontal>
                    <text text="{{user.time_off}}到期,购买后有效期将延顺" h="*" gravity="center_vertical" textColor="#80ffffff" />
                </vertical>
            </horizontal>
        )
    }
    ui.registerWidget("user_title-layout", userTitleLayout);
    return userTitleLayout;
})();

//自定义控件 付款方式
var payLayout = (function () {
    util.extend(payLayout, ui.Widget);
    function payLayout() {
        ui.Widget.call(this);
        this.defineAttr("name", (view, attr, value, defineSetter) => {
            view._pay_name.setText(value);
        });
        this.defineAttr("label", (view, attr, value, defineSetter) => {
            view._label_text.setText(value)
            switch (value) {
                case "推荐":
                    view._label_bg.attr("cardBackgroundColor", "#f5a623")
                    break;
                case "维护":
                    view._label_bg.attr("cardBackgroundColor", "#999999")
                    break;
            }
            view._label_bg.attr("visibility", "visible");
        })
        this.defineAttr("subtitle", (view, attr, value, defineSetter) => {
            view._subtitle.setText(value);
            view._subtitle.attr("visibility", "visible");
        });
        this.defineAttr("src", (view, attr, value, defineSetter) => {
            view._img.attr("src", value);
        });
        this.defineAttr("onClick", (view, name, defaultGetter) => {
            return this._onClick;
        }, (view, name, value, defaultSetter) => {
            v_pay_radio[v_pay_radio.length] = view._radio

            this._onClick = value;
        });
    }
    payLayout.prototype.render = function () {
        return (
            <vertical >
                <frame h="1" w="*" bg="#e3e3e3" />
                <horizontal marginTop="10" marginBottom="10" w="*" h="44" >
                    <img id="_img" w="44" src="#ffffff" />
                    <vertical h="*" w="auto" marginLeft="10">
                        <horizontal h="22" w="auto">
                            <text id="_pay_name" w="auto" text="未知" textSize="18" textStyle="bold" textColor="#000000" minWidth="60" />
                            <card id="_label_bg" w="auto" h="auto" marginLeft="10" layout_gravity="center_vertical" cardCornerRadius="6" cardBackgroundColor="#f5a623"
                                foreground="?selectableItemBackground" visibility="invisible">
                                <text id="_label_text" margin="10 0 10 0" text="暂无" textStyle="bold" textSize="14" textColor="#ffffff" />
                            </card>
                        </horizontal>
                        <text id="_subtitle" w="auto" h="*" gravity="bottom" text="暂无" textSize="12" visibility="invisible" />
                    </vertical>
                    <vertical w="*" h="*" gravity="right|center">
                        <radio id="_radio" w="auto" clickable="false" />
                    </vertical>
                </horizontal>
            </vertical>
        )
    };
    payLayout.prototype.onViewCreated = function (view) {
        view.on("click", () => {
            if (this._onClick) {
                for (let i = 0; i != v_pay_radio.length; i++) {
                    v_pay_radio[i].attr("checked", false);
                }
                if (view._label_text.text() == "维护") {
                    pay = 0
                    alert(view._pay_name.text() + "支付通道正在维护中")
                } else {
                    pay = view._pay_name.text()
                    view._radio.attr("checked", true)
                }

                eval(this._onClick);
            }
        });
    };
    ui.registerWidget("pay-layout", payLayout);
    return payLayout;
})();

//自定义控件 处理中toast
var remindLayout = (function () {
    util.extend(remindLayout, ui.Widget);
    function remindLayout() {
        ui.Widget.call(this);
        this.defineAttr("onClick", (view, name, defaultGetter) => {
            return this._onClick;
        }, (view, name, value, defaultSetter) => {
            remind = view
            this._onClick = value;
        });
    }
    remindLayout.prototype.render = function () {
        return (
            <frame id="_loads" w="*" h="*" >
                <card id="_load" h="150" w="150" cardBackgroundColor="#95000000" layout_gravity="center"
                    cardElevation="0" cardCornerRadius="10dp" alpha="0">
                    <frame >
                        <frame alpha="0.6">
                            <img id="_load_colse" w="70" h="70" src="@drawable/ic_sentiment_dissatisfied_black_48dp" layout_gravity="center" marginBottom="10" tint="#ffffff" alpha="0" />
                        </frame>
                        <frame id="_load_0">
                            <text id="_load_time" text="10" w="auto" h="auto" layout_gravity="center" marginBottom="10" textStyle="bold" textColor="#90ffffff" textSize="30" />
                            <progressbar w="80" h="80" layout_gravity="center" marginBottom="10" alpha="0.8" />
                        </frame>
                        <text id="_load_text" text="正在创建订单" w="auto" h="auto" marginBottom="10" layout_gravity="bottom|center" textStyle="bold" textColor="#90ffffff" textSize="16" />
                    </frame>
                </card>
            </frame>
        )
    }
    ui.registerWidget("remind-layout", remindLayout);
    return remindLayout;
})();

//自定义控件 支付弹窗ui
var orderLayout = (function () {
    util.extend(orderLayout, ui.Widget);
    function orderLayout() {
        ui.Widget.call(this);
        this.defineAttr("src", (view, attr, value, defineSetter) => {
            view._img.attr("src", value);

        });
        this.defineAttr("onClick", (view, name, defaultGetter) => {
            return this._onClick;
        }, (view, name, value, defaultSetter) => {
            order = view
            this._onClick = value;
        });
    }
    orderLayout.prototype.render = function () {
        return (
            <frame id="pay_bg_bg" w="*" h="*" bg="#000000" alpha="0" visibility="gone" >
                <vertical w="*" h="*" gravity="center_vertical" marginTop="-40">
                    <horizontal w="*" h="auto" weightSum="5" gravity="center" >
                        <card id="pay_bg" h="auto" w="auto" margin="0 40 0 40" layout_weight="2"
                            cardElevation="20" cardCornerRadius="25dp" cardBackgroundColor="#ffffff" alpha="0">
                            <vertical h="*" w="*" clipChildren="false">
                                <vertical h="*" w="*" marginBottom="30" >
                                    <horizontal marginTop="10" gravity="center_horizontal">
                                        <text text="支付时请核对下面订单号" textColor="#000000" />
                                    </horizontal>
                                    <text
                                        id="_data"
                                        marginTop="10"
                                        text="0"
                                        textColor="#000000"
                                        gravity="center_horizontal"
                                    />
                                    <horizontal w="*" h="150" weightSum="5" gravity="center_horizontal">
                                        <img id="_img" w="*" h="*" src="#ffffff" layout_weight="3" scaleType="fitCenter" layout_gravity="center_horizontal" />
                                    </horizontal>
                                    <text
                                        id="_pay_g"
                                        text="198.00"
                                        textColor="#000000"
                                        textStyle="bold"
                                        textSize="30"
                                        gravity="center"
                                    />
                                </vertical>
                                <vertical h="auto" w="*" layout_weight="1" bg="#00a0e8" >
                                    <img w="44" h="44" marginTop="-22" src="{{img_user}}" layout_gravity="center_horizontal" circle="true" borderWidth="2" borderColor="#ffffff" />
                                    <vertical marginLeft="20" marginTop="10">
                                        <text
                                            id="_user"
                                            h="auto"
                                            text="用户信息: "
                                            textColor="#ffffff"
                                            textSize="12"
                                        />
                                        <text
                                            id="_pay"
                                            h="*"
                                            text="订单信息: "
                                            textColor="#ffffff"
                                            textSize="12"
                                        />
                                        <text
                                            id="_date"
                                            h="*"
                                            text="创建时间: "
                                            textColor="#ffffff"
                                            textSize="12"
                                        />
                                    </vertical>
                                    <frame w="*" h="25" margin="0 10 0 10" gravity="center_horizontal">
                                        <text w="auto" h="*" text="已完成支付" textColor="#ffffff" gravity="center_vertical" />
                                        <img id="_validation" w="100" h="25" src="#00ffffff" borderWidth="1" borderColor="#ffffff" layout_gravity="center_horizontal" scaleType="fitXY" radius="20" />
                                    </frame>
                                </vertical>
                            </vertical>
                        </card>
                    </horizontal>
                    <frame id="_close" w="40" h="40" marginTop="-20" layout_gravity="center_horizontal" alpha="0.5" rotation="45">
                        <img w="*" h="*" src="#00ffffff" borderWidth="1" borderColor="#ffffff" layout_gravity="center_horizontal" scaleType="fitXY" radius="60" />
                        <vertical w="25" h="1" bg="#ffffff" layout_gravity="center" />
                        <vertical w="1" h="25" bg="#ffffff" layout_gravity="center" />
                    </frame>

                </vertical>
                <text
                    text="UI示例,@大柒 "
                    textColor="#80ffffff"
                    textSize="28"
                    textStyle="bold"
                    gravity="center_horizontal"
                    marginTop="20" />
                <vertical w="*" h="auto" layout_gravity="bottom">
                    <frame w="*" h="25" marginBottom="10" gravity="center_horizontal" alpha="0.5">
                        <text id="_intent_text" w="auto" h="*" text="本机支付" textColor="#ffffff" gravity="center_vertical" />
                        <img id="_intent" w="100" h="25" src="#00ffffff" borderWidth="1" borderColor="#ffffff" layout_gravity="center_horizontal" scaleType="fitXY" radius="20" />
                    </frame>
                    <text h="auto" text="扫描上方二维码进行付款" textColor="#80ffffff" gravity="center_horizontal" textSize="10" />
                    <text h="auto" text="付款完成后,点击已完成支付" textColor="#80ffffff" gravity="center_horizontal" textSize="10" />
                </vertical>
            </frame>
        )
    };
    orderLayout.prototype.onViewCreated = function (view, attr, value) {

    };
    ui.registerWidget("order-layout", orderLayout);
    return orderLayout;
})();


//ui界面
ui.layout(
    <vertical h="*" >
        <frame h="*" id="pay_0">
            <vertical h="*" w="*">
                <vertical h="auto">
                    <appbar >
                        <toolbar bg="{{MyColor}}" id="toolbar" fitsSystemWindows="true" h="75" >
                            <img h="35" id="pay_close" src="{{log_back}}" tint="#98ffffff" />
                            <text text="会员中心" textStyle="bold" textSize="18" textColor="#98ffffff" layout_gravity="center" />
                        </toolbar>
                    </appbar>
                </vertical>
                <scroll h="*" w="*" layout_gravity="center">
                    <vertical h="*" w="*" bg="#f5f6f8" >
                        <user_title-layout h="60" w="*" />
                        <vertical h="auto" w="*" bg="#ffffff"  >
                            <frame h="64" w="*" margin="10 0 10 0" >
                                <text h="*" w="auto" id="money_name" text="{{payName}}" textSize="22" textColor="#000000" textStyle="bold" layout_gravity="left" gravity="center_vertical" />
                                <frame h="*" w="auto" layout_gravity="right" >
                                    <text h="*" w="auto" id="pay_key" text="激活码续费 >" gravity="center_vertical" />
                                </frame>
                            </frame>
                            <horizontal h="auto" marginLeft="10" marginBottom="30" >
                                <setMeal-layout h="auto" w="*" layout_weight="1" title="赠一对一专属客服" month="12个月" money="198" subtitle="折合16.5/月" remind="最大优惠哦!" onClick="pay_bnt_color1()" />
                                <setMeal-layout h="auto" w="*" layout_weight="1" title="优惠很低" month="3个月" money="58" subtitle="折合19.3/月" onClick="pay_bnt_color1()" />
                                <setMeal-layout h="auto" w="*" layout_weight="1" month="1个月" money="19.8" onClick="pay_bnt_color1()" />
                            </horizontal>
                        </vertical>
                        <vertical w="*" h="auto" marginTop="10" bg="#ffffff">
                            <vertical margin="10 10 20 10">
                                <text text="付款方式" marginBottom="10" textSize="22" textStyle="bold" textColor="#000000" />
                                <pay-layout w="*" h="auto"
                                    name="支付宝"
                                    src="{{img_zfb}}"
                                    label="推荐"
                                    subtitle="数亿人都在用 , 安全可托付"
                                    onClick="pay_bnt_color1()"
                                />
                                <pay-layout w="*" h="auto"
                                    name="微信"
                                    src="{{img_wx}}"
                                    label="维护"
                                    subtitle="诚信1+1 , 支付百分百"
                                    onClick="pay_bnt_color1()"
                                />
                            </vertical>
                        </vertical>
                        <vertical w="*" h="100" />
                    </vertical>
                </scroll>
                <card h="60" w="*" bg="#f5f6f8" marginTop="-60" layout_gravity="bottom"
                    cardElevation="30">
                    <horizontal h="*" w="*" >
                        <vertical h="*" w="*" layout_weight="1" marginLeft="20">
                            <horizontal w="*" h="40">
                                <text text="总计:" h="*" w="auto" textSize="20" gravity="center_vertical" textColor="#000000" />
                                <text text="¥" textSize="20" marginLeft="10" gravity="center_vertical" textColor="#b48c51" />
                                <text id="money" text="0.00" textSize="30" textStyle="bold" gravity="center_vertical" textColor="#b48c51" />
                            </horizontal>
                            <frame w="*" h="20" >
                                <text id="money_s" text="请选择套餐" />
                            </frame>
                        </vertical>
                        <vertical id="pay_bnt_bg" h="*" w="*" layout_weight="2" bg="{{pay_bnt.s.bg}}" gravity="center">
                            <text id="pay_bnt_color" text="确认支付" textStyle="bold" textSize="20" gravity="center" textColor="{{pay_bnt.s.color}}" />
                        </vertical>
                    </horizontal>
                </card>

            </vertical>
            <remind-layout w="*" h="*" onClick="" />
            <order-layout w="*" h="*" onClick="" />
        </frame>
    </vertical>
);

var pay = 0
var pay_money = 0
var int_0 = 0, int_1 = 0
var load_time = 10
var load_pay = false
var pay_key = {}
var uname
var get_url = "http://shangtai0115.vicp.io:45981/"


ui.pay_bnt_bg.on("click", () => {
    if (load_pay) { toast("请不要重复提交订单"); return };
    if (!pay_money) { dialogs.alert("请选择续费套餐"); return };
    if (!pay) { dialogs.alert("请选择支付方式"); return };
    ui.run(function () {
        remind._load_colse.attr("alpha", "0")
        remind._load_text.setText("正在创建订单")
        remind._load_0.attr("alpha", "1")
        load_time = 10
        remind._load_time.setText("10")
        dialogs.select("请选择预执行的动作", ["生成订单", "生成赞赏码"])
            .then(i => {
                switch (i) {
                    case 0:
                        let get = "open-get?flag=测试订单&"
                        get += "user=" + user.name + "&"
                        get += "id=" + user.id + "&"
                        get += "data=" + pay_money + "&"
                        get += "pay=支付宝"
                        uname = "购买" + pay_money + "个月" + payName
                        gethttp(get)
                        break;
                    case 1:
                        rawInput("请输入要赞赏的金额").then(age => {
                            let A = age
                            //let A = parseFloat(age)
                            if (isNaN(A) || A == null || A <= 0) { log("错误"); alert("请输入正确金额"); return }
                            let get = "open-get?flag=自定义赞赏&"
                            get += "user=" + user.name + "&"
                            get += "id=" + user.id + "&"
                            get += "data=" + A + "&"
                            get += "pay=支付宝"
                            uname = "自定义赞赏"
                            gethttp(get)
                        });
                        break;
                }
            });
    })
    function gethttp(data) {
        remind._loads.attr("clickable", true);
        load_pay = true
        //采用回调方式GET请求
        http.get(get_url + data, {}, function (res, err) {
            if (err) {
                console.error(err);
                return;
            }
            pay_key = res.body.json()
            http.get(pay_key.url_logo, {}, function (res1, err) {
                if (err) {
                    console.error(err);
                    return;
                }
                let AA1 = res1.body.string()
                var pattern = "qrcode_plugins_img =\"(.*)\"";
                pay_key.img = AA1.match(pattern)[1];
                //log("html = " + pay_key.img);
                pay_loading()
            });
        });
        //定时器倒计时
        remind._load.attr("alpha", "1");
        int_0 = setInterval(function () {
            if (!load_pay) { toast_load_colse(); clearInterval(int_0); }
            if (load_time == 0) {
                ui.run(function () {
                    remind._load_colse.attr("alpha", "1")
                    remind._load_0.attr("alpha", "0")
                    remind._load_text.setText("创建订单失败")
                    clearInterval(int_0);
                })
                setTimeout(function () {
                    toast_load_colse()
                }, 2000);
                return
            }
            load_time--
            remind._load_time.setText("" + load_time)
        }, 1000);
    }
})

ui.pay_key.on("click", () => {
    log("激活码续费")
    alert("UI示例文件,不支持激活码续费")
})

ui.pay_close.on("click", () => {
    toastLog("ui关闭")
    exit()
})

function toast_load_colse() {
    ui.run(function () {
        remind._load.attr("alpha", "0")
        clearInterval(int_0);
        load_pay = false
        remind._loads.attr("clickable", false);
    })
}

function pay_bnt_color1() {
    ui.run(function () {
        if (pay && pay_money) {
            ui.pay_bnt_bg.attr("bg", pay_bnt.c.bg)
            ui.pay_bnt_color.setTextColor(colors.parseColor(pay_bnt.c.color))
        } else {
            ui.pay_bnt_bg.attr("bg", pay_bnt.s.bg)
            ui.pay_bnt_color.setTextColor(colors.parseColor(pay_bnt.s.color))
        }
    })
}

function pay_loading() {
    ui.run(function () {
        order._img.attr("src", "http:" + pay_key.img)
        order._user.setText('用户信息: ' + user.name + ' ID: ' + user.id)
        order._pay.setText('订单信息: ' + uname)
        order._date.setText('创建时间: ' + pay_key.date)
        order._pay_g.setText(keepTwoDecimalFull(pay_key.pay))
        order._data.setText(str_key(pay_key.data, 4))
    })
    sleep(2000)
    toast_load_colse()
    load_pay = true
    ui.run(function () {
        order.pay_bg_bg.attr("visibility", "visible");
        order.pay_bg_bg.attr("clickable", true);
        slX = ObjectAnimator.ofFloat(order.pay_bg, "scaleX", 0, 1)
        slY = ObjectAnimator.ofFloat(order.pay_bg, "scaleY", 0, 1)
        animator = ObjectAnimator.ofFloat(order.pay_bg, "alpha", 1, 1)
        animator1 = ObjectAnimator.ofFloat(order.pay_bg_bg, "alpha", 0, 1)
        set = new AnimatorSet()
        set.playTogether(
            slX, slY, animator, animator1);
        set.setDuration(animation_time);
        set.start();
    })
}

/**
 * 支付页面 控件触发
 */
order._intent.on("click", () => {
    log("跳转支付宝")
    try {
        app.startActivity({
            data: pay_key.url
        });
        toast("正在打开支付宝")
    } catch (error) {
        toast("没有安装支付宝")
    }

});

order._close.on("click", () => {
    log("点击>>>关闭")
    confirm("确定要关闭吗").then(value => {
        //当点击确定后会执行这里, value为true或false, 表示点击"确定"或"取消"
        if (value) {
            slX = ObjectAnimator.ofFloat(order.pay_bg, "scaleX", 1, 0)
            slY = ObjectAnimator.ofFloat(order.pay_bg, "scaleY", 1, 0)
            animator = ObjectAnimator.ofFloat(order.pay_bg, "alpha", 1, 1)
            animator1 = ObjectAnimator.ofFloat(order.pay_bg_bg, "alpha", 1, 0)
            set = new AnimatorSet()
            set.playTogether(
                slX, slY, animator, animator1);
            set.setDuration(animation_time);
            set.start();
            setTimeout(function () {
                load_pay = false
                ui.run(function () {
                    order.pay_bg_bg.attr("clickable", false);
                    order.pay_bg_bg.attr("visibility", "gone");
                })
            }, animation_time);
        }
    });
})

order._validation.on("click", () => {
    log("效验结果")
    alert("UI示例文件,不支持支付结果效验")
})

function keepTwoDecimalFull(num) {
    var result = parseFloat(num);
    if (isNaN(result)) {
        alert('传递参数错误,请检查!');
        return false;
    }
    result = Math.round(num * 100) / 100;
    var s_x = result.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
        s_x += '0';
    }
    return s_x;
}

function str_key(source, count) {
    let arr = [];
    for (let i = 0, len = source.length / count; i < len; i++) {
        let subStr = source.substr(0, count);
        arr.push(subStr);
        source = source.replace(subStr, "");
    }
    let str = ""
    for (i = 0; i < arr.length - 1; i++) {
        str += arr[i] + " "
    }
    return str + arr[arr.length - 1]
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683
  • 684
  • 685
  • 686
  • 687
  • 688
  • 689
  • 690
  • 691
  • 692
  • 693
  • 694
  • 695
  • 696
  • 697
  • 698
  • 699
  • 700
  • 701
  • 702
  • 703
  • 704
  • 705
  • 706
  • 707
  • 708
  • 709
  • 710
  • 711
  • 712
  • 713
  • 714
  • 715
  • 716
  • 717
  • 718
  • 719
  • 720
  • 721
  • 722
  • 723
  • 724
  • 725
  • 726
  • 727
  • 728
  • 729
  • 730
  • 731
  • 732
  • 733
  • 734
  • 735
  • 736
  • 737
  • 738
  • 739
  • 740
  • 741
  • 742
  • 743
  • 744
  • 745
  • 746
  • 747
  • 748
  • 749
  • 750
  • 751
  • 752
  • 753
  • 754
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/111698
推荐阅读
相关标签
  

闽ICP备14008679号