8.红包能力

UnityDemo 【红包&红包群】中有相关使用示例。

  • 需要先设置回调,再调用具体的功能接口,具体使用参考下面【示例】。

  • 回调函数参数介绍

    result: 成功true;失败false

    info:返回json字符串

8.1 域名配置

域名分为游戏和应用,默认使用游戏域名配置。

Unity

Wb.CashManager.Instance.setDomainType(DomainType type);

示例:

setDomainType.GetComponent<Button>().onClick.AddListener(delegate ()
{
    string outStr;
    if (LanguageManagers.Instance.languageDic.TryGetValue("域名配置", out outStr))
    {
        string outStr1;
        if (LanguageManagers.Instance.languageDic.TryGetValue("0游戏1应用", out outStr1))
        {
            HomeManager._homeManager.showInputDialogWithPreValue(outStr + ":" + outStr1, (domainType == 0) ? "1" : "0", inputValue =>
                {
                    if (inputValue.Equals("0") || inputValue.Equals("1"))
                    {
                        int tmp;
                        int.TryParse(inputValue, out tmp);
                        if (0 == tmp || 1 == tmp)
                        {
                            domainType = tmp;
                            setDomainBtnTxt();
                            if (0 == tmp)
                            {
                                Wb.CashManager.Instance.setDomainType(Wb.DomainType.Game);
                            }
                            else
                            {
                                Wb.CashManager.Instance.setDomainType(Wb.DomainType.App);
                            }
                        }
                        else
                        {
                            string outStr2;
                            if (LanguageManagers.Instance.languageDic.TryGetValue("域名类型设置错误!", out outStr2))
                            {
                                ShowToast(outStr2, true);
                            }
                        }
                    }
                    else
                    {
                        string outStr2;
                        if (LanguageManagers.Instance.languageDic.TryGetValue("域名类型设置错误!", out outStr2))
                        {
                            ShowToast(outStr2, true);
                        }
                    }
                });
        }
    }
});
  • 参数:

    type:Wb.DomainType.Game(游戏)或 Wb.DomainType.App(应用)

返回信息: 无

8.2 提交余额

上报提现余额

Unity

Wb.CashManager.Instance.reportBalance(int redBalance, int videoNumbs)

示例:

  // 先设置回调
  Wb.CashManager.Instance.GetRedPacketInfo((result, info) =>
  {
      if (result)
      {
          responseTxt.GetComponent<Text>().text = info.ToString();
          string outStr1;
          if (LanguageManagers.Instance.languageDic.TryGetValue("提交余额成功", out outStr1))
          {
              ShowToast(outStr1, false);
          }
      }
      else
      {
          responseTxt.GetComponent<Text>().text = info.ToString();
          string outStr1;
          if (LanguageManagers.Instance.languageDic.TryGetValue("提交余额失败", out outStr1))
          {
              ShowToast(outStr1, true);
          }
      }
  });
  int coin = 0;
  int.TryParse(inputValue, out coin);
  if (coin >= 1)
  {
      // 上报余额
      int num = Wb.ADManager.Instance.GetVideoLimitOpenNum();
      Wb.CashManager.Instance.reportBalance(coin, num);
  }
  else
  {
      string outStr1;
      if (LanguageManagers.Instance.languageDic.TryGetValue("只能为正整数!", out outStr1))
      {
          ShowToast(outStr1, true);
      }
  }
  • 参数: redBalance:上报的金额单位为分 videoNumbs:广告剩余视频播放次数

  • 返回信息:

{
    "error":int --处理结果0:成功;1:失败;
    "msg":str --错误信息

    "redBalance" :int --纠正的红包余额,单位为分
    "maxBalance" : int  --普通用户为0(使用客户端上限值),幸运用户为可触发提现的上限值,比如2500
    "loginDays": int --连续登陆天数。第一天返回1,第二天返回2,第三天没来,第四天再来返回1
    "sign":str --服务器返回值签名,md5(lsn+appid+pid+imei+redBalance+maxBalance+resMd5Key)转小写
}

8.3 获取提现配置

Unity

Wb.CashManager.Instance.getCashConfig();

示例:

// 先设置回调
Wb.CashManager.Instance.GetRedPacketInfo((result, info) =>
{
    if (result)
    {
        responseTxt.GetComponent<Text>().text = info.ToString();
        string outStr1;
        if (LanguageManagers.Instance.languageDic.TryGetValue("获取提现配置信息成功", out outStr1))
        {
            ShowToast(outStr1, false);
        }
    }
    else
    {
        responseTxt.GetComponent<Text>().text = info.ToString();
        string outStr1;
        if (LanguageManagers.Instance.languageDic.TryGetValue("获取提现配置信息失败", out outStr1))
        {
            ShowToast(outStr1, true);
        }
    }
});
// 获取提现配置
Wb.CashManager.Instance.getCashConfig();
  • 参数: 无

  • 返回信息:

{
    "error":int --处理结果0成功1失败
    "errmsg":str --错误原因,成功时可为空
    "data" : {
        "timestamp": "1578369244355",
        "loginDays": 2,
        "descriptionUrl": "http://www.baidu.com",
        "withdrawActivity":[
            {"amount": 0.3,"desc": "提现需要微信实名制","type": 1, "isComplete": false},
            {"amount": 1, "desc": "提现需要微信实名制","type": 2, "isComplete": false},
            {"amount": 20,"desc": "提现需要微信实名制","type": 3, "isComplete": false}
        ],
        "withdrawHistory":[
            {"date": "2017-12-11 15:05:07","amount": "0.30元", "desc": "已发放"},
            {"date": "2017-12-11 15:05:07","amount": "0.20元", "desc": "已发放"},
            {"date": "2017-12-11 15:05:07","amount": "0.10元", "desc": "已发放"}
        ],
        "sign":"c4ca4238a0b923820dcc509a6f75849b"
    }
}

// isComplete:是否已提现,true-已提现  false-未提现
// loginDays: 连续登陆天数
// descriptionUrl:“提现说明“链接
// type: 提现活动类型 0-不可提现  1-积分任务 2-连续登陆任务 3-大额现金提现,10~20元左右(100次视频,余额10元以上可能开启) 4-超大额现金提现,20~30元左右(200次视频,余额20元以上可能开启)  5-无条件提现 6-积分任务的补充
// withdrawActivity:提现活动配置
// withdrawHistory:提现历史记录
// sign:md5(lsn+appid+pid+imei+timestamp+resMd5Key)转小写

8.4 发起提现

需登录微信才可以提现

Unity

Wb.CashManager.Instance.cashMoney(int type, string openid, string accessToken, float amount, int withdrawType);

示例:

    Wb.SocialManager.Instance.Login(type, (result) =>
    {
        if (result)
        {
            //获取用户信息异步操作
            GetUserInfo(type);
        }
        else
        {
            string outStr1;
            if (LanguageManagers.Instance.languageDic.TryGetValue("登录失败", out outStr1))
            {
                ShowToast(outStr1, true);
            }
        }
    });

    private void GetUserInfo(int type)
    {
        Wb.SocialManager.Instance.GetUserInfo(type, (result, info) =>
        {
            if (result)
            {
                CashMoney(info.GetOpenId(), info.GetAccessToken());
            }
            else
            {
                string outStr1;
                if (LanguageManagers.Instance.languageDic.TryGetValue("获取用户信息失败", out outStr1))
                {
                    ShowToast(outStr1, true);
                }
            }
        });
    }

    private void CashMoney(string openid, string accesstoken)
    {
        string outStr;
        if (LanguageManagers.Instance.languageDic.TryGetValue("发起提现", out outStr))
        {
            HomeManager._homeManager.showInputDialogWithPreValue(outStr, "0.3", inputValue =>
            {
                if (!inputValue.Equals(""))
                {
                    Wb.CashManager.Instance.GetRedPacketInfo((result, info) =>
                    {
                        if (result)
                        {
                            responseTxt.GetComponent<Text>().text = info.ToString();
                            string outStr1;
                            if (LanguageManagers.Instance.languageDic.TryGetValue("发起提现成功", out outStr1))
                            {
                                ShowToast(outStr1, false);
                            }
                        }
                        else
                        {
                            responseTxt.GetComponent<Text>().text = info.ToString();
                            string outStr1;
                            if (LanguageManagers.Instance.languageDic.TryGetValue("发起提现失败", out outStr1))
                            {
                                ShowToast(outStr1, true);
                            }
                        }
                    });
                    float coin = 0;
                    float.TryParse(inputValue, out coin);
                    if (coin > 0.000001f)
                    {
                        Wb.CashManager.Instance.cashMoney(1, openid, accesstoken, coin, 0);
                    }
                    else
                    {
                        string outStr1;
                        if (LanguageManagers.Instance.languageDic.TryGetValue("数据不对!", out outStr1))
                        {
                            ShowToast(outStr1, true);
                        }
                    }
                }
                else
                {
                    string outStr1;
                    if (LanguageManagers.Instance.languageDic.TryGetValue("数据不对!", out outStr1))
                    {
                        ShowToast(outStr1, true);
                    }
                }
            });
        }
    }
  • 参数: type:提现活动类型 openid:微信openid或者支付宝openid accessToken:微信的授权Token或者支付宝token amount:提现金额,例如0.3 withdrawType:提现到账方式 0 wechat、1 alipay

  • 返回信息:

{
    error:int --处理结果0成功1失败
    errmsg:str --错误原因,成功时可为空
    msg:str --描述文字,例如提现成功,1-3小时微信到账/红包余额不足/openid错误/未满足提现条件
    "withdrawHistory":[
        {"date": "2017-12-11 15:05:07","amount": "0.30元", "desc": "已发放"},
        {"date": "2017-12-11 15:05:07","amount": "0.20元", "desc": "已发放"},
        {"date": "2017-12-11 15:05:07","amount": "0.10元", "desc": "已发放"}
    ]
}

最后更新于