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