zoukankan      html  css  js  c++  java
  • 字节跳动小程序的一些坑

    1.激励视频广告支持版本

    抖音安卓 10.3 及以上,抖音 iOS10.7 及以上 ,需要通过 tt.getSystemInfoSync() 判断版本号 。

    // 抖音版本 验证
    function validVer() {
      let sys = tt.getSystemInfoSync();
      console.log(version, sys.appName, sys.platform, sys.version, sys);
      // 为 true   不支持激励视频广告
      if (sys.appName !== "Douyin") {
        return true;
      }
      // 安卓抖音10.30支持  IOS 10.70支持 激励视频
      //......
    }

    2.小程序广告相关设置

    1.激励视频

    /* 需先做版本判断处理 */ 
    if (!this.verFlag) {
        // 抖音 
        this.showModel();
    }
    else { / 头条 or 低版本 }
    /* 全局 */
    const videoAd = null;
    
    //...
    
    /* 初始化广告对象 */
    initTTAd() {
      let that = this;
      if (tt.createRewardedVideoAd) {
        /* 设置广告对象 */
        videoAd = tt.createRewardedVideoAd({
          adUnitId: "广告ID",
        });
        /* 捕捉错误 */ 
        videoAd.onError((err) => {
          console.log(err.errCode);
          if (err.errCode == "1004") {
            // 暂时没有合适的广告,请稍后在试
          }
        });
        /* 监听广告关闭 */
        videoAd.onClose((res) => {
          if (res.isEnded) {
            //成功 给予奖励
          } else {
            // 中途关闭
          }
        });
      }
    }

    !!字节小程序激励视频全局只全局只有一个videoAd实例,重复创建没有用 只能抖音加载激励视频

    不同页面使用可能会冲突 参考封装的方法⬇️


    <https://www.cnblogs.com/ZeroShiro/p/13530805.html>

     2.AD组件

    <!-- AD组件支持只头条小程序 , 可通过外部view设置样式 -->
    <view class="ad" v-if="touTAD">
              <ad
                unit-id="广告ID"
                ad-intervals="100"
                bindload="adloadhandler"
                binderror="aderrorhandler"
                bindclose="adclosehandler"
              ></ad>
    </view>

    3.输入框违规字段验证 (走后端)

    先获取token 

    GET https://developer.toutiao.com/api/apps/token

    POST https://developer.toutiao.com/api/v2/tags/text/antidirt

    let url = "https://developer.toutiao.com/api/v2/tags/text/antidirt";
    /* 验证字段 */
    let data = {
            tasks: [
              {
                content: v,
              },
            ],
     };
    /* 发送请求 */
    // .......
    {
              url: url,
              method: "POST",
              token: token,
              data: data,
     }
    //请求成功 验证 prob 字段
    let data = res.data.data;
    let flag
    = data.some((item, index) => { // 有一个是 1 表示有不合字段 return item.predicts[0].prob == 1; });

    4.微信H5支付 pay

    ios暂不支持虚拟支付 需要做判断

    // 微信支付成功后
    function tPay(res, ip = "127.0.0.1", out) {
      // 获取支付链接 分解 xml
      let mweb_url = getXMLNodeValue("mweb_url", res.data.toString("utf-8"));
    
      // 字节支付 secret
      let key = "xxxxxxx";
      // 字节需要的字段
      let orderInfo = {
        app_id: "80085xxxx", //头条支付分配给商户 app_id
        body: "xx订单", //商户订单详情
        currency: "CNY", //固定值: CNY。币种
        merchant_id: "190xxxx", //头条支付分配给商户的商户号,
        notify_url: `http://tp-pay.snssdk.com/cashdesk/test/paycallback`, //填任意非空 URL 即可(具体看官网)
        out_order_no: out, // 商户订单号
        payment_type: "direct", //固定值:direct
        product_code: "pay", //固定值:pay
        sign_type: "MD5", //固定值:MD5。
        subject: "xx订单", //商户订单名称
        timestamp: createTimeStamp(), //发送请求的时间戳,精确到秒,
        total_amount: 100, // 金额,整型,单位:分(不能有小数)
        trade_time: createTimeStamp(), //下单时间戳,精确到秒
        trade_type: "H5", //固定值:H5
        uid: "80085xxxx", // uid 可和 app_id 一样
        valid_time: "300", // 订单有效期
        version: "2.0", //固定值:2.0
        wx_type: "MWEB", //wx_url 非空时传 'MWEB'。wx_url 为空时,该字段不传
        wx_url: mweb_url, // mweb_url 字段值  微信返回的支付链接 https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx2016121516420242444321ca0631331346&package=1405458241
      };
      // 排序
      let reStr = sortStr(orderInfo, key, false);
      // 获取 签名
      let sign = nodMd5(reStr);
      orderInfo.sign = sign;
      // ip 不参与签名
      orderInfo.risk_info = `{"ip":"${ip}"}`;
      return orderInfo;
    }

     H5支付详细参考
     https://www.cnblogs.com/ZeroShiro/p/13305716.html

  • 相关阅读:
    ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending
    如何从vss中分离程序
    String or binary data would be truncated
    the pop3 service failed to retrieve authentication type and cannot continue
    The POP3 service failed to start because
    IIS Error he system cannot find the file specified _找不到页面
    pku2575Jolly Jumpers
    pku2940Wine Trading in Gergovia
    pku3219二项式系数
    pku1029false coin
  • 原文地址:https://www.cnblogs.com/ZeroShiro/p/12874430.html
Copyright © 2011-2022 走看看