api: Add CodeBatch.mini_prog_entry_path

This commit is contained in:
Fam Zheng 2025-03-01 13:04:58 +00:00
parent c5c8170b1f
commit 11599ec1e5
4 changed files with 24 additions and 3 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2025-03-01 13:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('products', '0095_auto_20250215_1138'),
]
operations = [
migrations.AddField(
model_name='codebatch',
name='mini_prog_entry_path',
field=models.TextField(blank=True, default='pages/index/index', null=True, verbose_name='小程序入口路径(可选)'),
),
]

View File

@ -8,11 +8,11 @@ def get_token():
r = requests.get(url)
return r.json()['access_token']
def mplink(query):
def mplink(query, path='pages/index/index'):
token = get_token()
url = 'https://api.weixin.qq.com/wxa/generate_urllink?access_token=' + token
r = requests.post(url, json={
'path': 'pages/index/index',
'path': path,
'query': query,
'expire_type': 1,
'expire_interval': 30,

View File

@ -176,6 +176,8 @@ class CodeBatch(models.Model):
verbose_name="自定义扫码重定向URL可选")
enable_auto_torch = models.BooleanField(default=False, verbose_name="自动打开闪光灯")
camera_sensitivity = models.FloatField(default=1.0, verbose_name="摄像头灵敏度")
mini_prog_entry_path = models.TextField(null=True, blank=True, default='pages/index/index',
verbose_name="小程序入口路径(可选)")
def gen_code(self, n):
a = 10 ** (self.num_digits - 1)

View File

@ -1243,7 +1243,8 @@ def mini_prog_entry_redirect(code, tid):
return redirect(sc.batch.scan_redirect_url)
query = 'tenant=' + str(tid)
key = 'mini-prog-entry.' + query
url = cache.get_or_set(key, lambda: mplink(query), 300)
path = code.batch.mini_prog_entry_path or 'pages/index/index'
url = cache.get_or_set(key, lambda: mplink(query, path), 300)
return redirect(url)
class MiniProgEntryView(BaseView):