生成小程序码的时候增加参数
This commit is contained in:
parent
eb8dea1ddf
commit
446d962fd8
@ -192,7 +192,7 @@ class ShopController extends BaseController {
|
||||
@permission('shop:edit')
|
||||
@router('post /api/shop/gameqr')
|
||||
async getGameQr(req: any) {
|
||||
let { shop, gameId, version } = req.params
|
||||
let { shop, gameId, version, params } = req.params
|
||||
if (isObjectId(shop)) {
|
||||
let record = await Shop.findById(shop)
|
||||
if (!record) {
|
||||
@ -200,7 +200,7 @@ class ShopController extends BaseController {
|
||||
}
|
||||
shop = record.sid
|
||||
}
|
||||
const { url } = await generateQrFile({ gameId, version, shop })
|
||||
const { url } = await generateQrFile({ gameId, version, shop, params })
|
||||
return { url }
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class ShopController extends BaseController {
|
||||
if (!sid) {
|
||||
throw new ZError(10, `shopInfo 没有店铺id: ${sid}`)
|
||||
}
|
||||
const shopId = sid.split('|')[0]
|
||||
const shopId = sid.split('_')[0]
|
||||
if (!validShopId(shopId)) {
|
||||
throw new ZError(10, `shopInfo 没有店铺id或者店铺id格式不正确: ${shopId}`)
|
||||
}
|
||||
|
@ -19,9 +19,27 @@ export function generateUploadPath(subPath: string) {
|
||||
* @param {string} shop
|
||||
* @return {{file: string, url: string}}
|
||||
*/
|
||||
export async function generateQrFile({ gameId, version, shop }: { gameId: string; version: string; shop: string }) {
|
||||
export async function generateQrFile({
|
||||
gameId,
|
||||
version,
|
||||
shop,
|
||||
params,
|
||||
}: {
|
||||
gameId: string
|
||||
version: string
|
||||
shop: string
|
||||
params: string[]
|
||||
}) {
|
||||
let subPath = `/qr/${gameId}/${version}`
|
||||
let paramStr = shop
|
||||
if (params && params.length > 0) {
|
||||
for (let _p of params) {
|
||||
subPath += `/${_p}`
|
||||
paramStr += `_${_p}`
|
||||
}
|
||||
}
|
||||
let path = generateUploadPath(subPath)
|
||||
|
||||
let file = `${path}/${shop}.png`
|
||||
let url = `${config.file.show_url}${subPath}/${shop}.png`
|
||||
if (jetpack.exists(file) !== 'file') {
|
||||
@ -29,12 +47,16 @@ export async function generateQrFile({ gameId, version, shop }: { gameId: string
|
||||
if (!versionData || !versionData.appid || !versionData.appsecret) {
|
||||
throw new ZError(20, 'game version not found')
|
||||
}
|
||||
await generateQr({
|
||||
if (paramStr.length > 30) {
|
||||
throw new ZError(21, '参数超过30个字符')
|
||||
}
|
||||
let result = await generateQr({
|
||||
appId: versionData.appid,
|
||||
appSecret: versionData.appsecret,
|
||||
scene: shop,
|
||||
scene: paramStr,
|
||||
file,
|
||||
})
|
||||
console.log(result)
|
||||
}
|
||||
return { file, url }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user