当前位置:网站首页>[ByteDance] ByteDance access (including login and payment)
[ByteDance] ByteDance access (including login and payment)
2022-07-24 08:12:00 【sirria1】
Environmental Science :
client :cocos creator2.4.3
The server :openresty
Official website :https://microapp.bytedance.com/docs/zh-CN/mini-game/develop/open-capacity/log-in/tt-login
1. Sign in . Anonymous login cannot be used at present, and authorization must be enforced .
client : Use the official sample code .
tt.login({
force: true,
success(res) {
console.log(`login Successful call ${res.code} ${res.anonymousCode}`);
},
fail(res) {
console.log(`login Call failed `);
},
});obtain code Log in .
The server : Login in exchange for openid
function utils.request_verify_session_byte(code, anonymous_code)
local httpc = http.new()
local params = "appid="..byteapppid.."&secret="..bytesecret.."&code="..code
return httpc:request_uri("https://developer.toutiao.com/api/apps/jscode2session?"..params, {
method = "GET",
})
end
-- byteappid Bytes of app id
-- bytesecret Bytes of secret id
-- code Obtained by client login
-- Successfully returns open id2. payment
preparation : Set the payment parameters in the byte management background

Before the client calls up the payment interface , You need to create an order from your server , Order obtained ID:order_id.
Client process :
1. Request the development backend to create an order order_id.
2. Transfer payment :
let payData = {
mode: 'game', // Payment type
env: 0, // Payment environment
currencyType: "CNY", // currency : At present, it's only for "CNY"
platform: "android", // The platform when applying for access : At present, it's only for "android"
buyQuantity: buyData.productPrice, // Purchase quantity , Must satisfy : Number of gold coins * The unit price of gold coins = Limit the price level ( For details, please refer to the limited level of gold coins )
zoneId: "1",
customId: orderID, // Developer defined unique order number . If not filled , The payment result callback will not contain this field , Game developers will not be able to distribute game props , The basic library version is lower than 1.55.0 There is no such field
extraInfo: JSON.stringify({
userId: userID, // User defined additional information , The payment result callback information contains this field , The basic library version is lower than 1.55.0 There is no such field
version: "v0.0.0",
price: productPrice,
}),//extraInfo To convert to a string
success(res) {
console.log(" ByteDance payment call succeeded :", res);
},
fail(res) {
console.log(" ByteDance payment call failed :", res);
},
}
tt.requestGamePayment(payData)3. After successful payment , The byte server will call back the callback address configured in the previous page . By the way , After the callback address is configured , Need to verify on the page , verification req The parameters of are placed in query Inside , The processing code looks like this (openresty)
pay_router:get("/cb", function(req, res, next)
local signature = ngx.escape_uri(req.query["signature"])
local msg = ngx.escape_uri(req.query["msg"])
local echostr = ngx.escape_uri(req.query["echostr"])
local nonce = ngx.escape_uri(req.query["nonce"])
local timestamp = ngx.escape_uri(req.query["timestamp"])
local token = cfg.bytetoken
local params = {token, timestamp, nonce, msg}
table.sort(params)
local str = table.concat(params)
local sign = string.lower(utils.bin2hex(ngx.sha1_bin(str)))
if sign == signature then
ngx.log(ngx.ERR, "byte get cb success")
else
ngx.log(ngx.ERR, "byte get cb failed.data=", utils.json_encode(req),".our sign:", sign, ",byte sign:", signature)
end
ngx.print(echostr)
end)When paying formally , The callback is initiated by POST Method , The interface name remains unchanged , The processing code looks like this :
pay_router:post("/cb", function(req, res, next)
local body = req.body
local token = cfg.bytetoken
ngx.log(ngx.ERR, "bytepay cb: req:", utils.json_encode(req))
local params = {token, body.timestamp, body.nonce, body.msg}
table.sort(params)
local str = table.concat(params)
local sign =string.lower(utils.bin2hex(ngx.sha1_bin(str)))
if body.signature == sign then
ngx.log(ngx.ERR, "bytepay check signature ok")
local status = 'success'
local msg = utils.json_decode(body.msg)
-- Recharge OK, Issue recharge items .
local ret = game_pay(utils.json_decode(msg.cp_extra).userId, msg.cp_orderno)
if ret.errCode ~= 0 then
res:json({''})
else
res:json({body.echostr})
end
else
ngx.log(ngx.ERR, "bytepay pay cb sign check err. own sign= ", sign, ".byte sign=", body.signature)
res:json({''})
end
end)Other interfaces can be supplemented by referring to official documents , For example, get player recharge currency , Poll for supplement, etc .
边栏推荐
- Use of ArrayList
- Debug No3 multi texture overlay
- The difference between online learning and offline learning
- 加密熊市:有人大举扩张 有人裁员收缩
- Figure New Earth: how to import CAD files with modified elevation datum (ellipsoid)
- Code=6 'The connection has timed out unexpectedly
- Learning to track at 100 FPS with deep progression networks
- About the big hole of wechat applet promise
- 【MATLAB】(三)MATLAB在高等数学中的应用
- Recognition and storage of Graphs
猜你喜欢

Debug No3 multi texture overlay

The vision group of Hegong University Sky team trained Day1 - machine learning, and learned to use the Yolo model

nacos报错: ERROR Nacos failed to start, please see D:\nacos\logs\nacos.log for more details.

*Code understanding * common function parsing in pytoch

Vidar-Team战队专访:AS WE DO, AS YOU KNOW.

Image feature SIFT (scale invariant feature transform)
![[shutter] the shutter doctor reports an error](/img/09/20279b3ed71a18b28566ddbe212597.png)
[shutter] the shutter doctor reports an error

SVG 从入门到后悔,怎么不早点学起来(图解版)

As skillfully uses idea annotation to improve collaboration / development efficiency

OpenGL camera and periodic review
随机推荐
Thesis reading: geotransformer
UVA572油田 Oil Deposits题解
Summary of study notes (I)
Intelligent robot and intelligent system (Professor Zhengzheng of Dalian University of Technology) -- 5. Bionic robot
Decision tree - ID3, C4.5, cart
(dkby) DFL learning notes
Debug No3 multi texture overlay
MySQL -- subquery scalar subquery
Wechat applet subscription message development process
Intelligent robots and intelligent systems (Professor Zhengzheng of Dalian University of Technology) -- 3. Industrial robots
[Linux] Oracle VirtualBox installation CentOS 8
Full revolutionary Siamese networks for object tracking translation
Android kotlin uses a coroutine instead of a callback function (suspendcoroutine usage)
Robert operator, Sobel operator, Laplace operator
Kotlin coroutine (II): scope and cancellation
Hegong sky team vision training Day2 - traditional vision, opencv basic operation
Wechat applet file types and functions
Detailed notes on pytoch building neural network
13.Unity2D 横版 可上下左右移动的双向平台(双向行走+可移动+单独判定)+随机平台生成
Qt|字符串生成二维码功能