Add mini_prog_entry_env_version

This commit is contained in:
Fam Zheng 2025-03-01 18:14:41 +00:00
parent c825852f77
commit 692a552fc1
5 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2025-03-01 18:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('products', '0096_codebatch_mini_prog_entry_path'),
]
operations = [
migrations.AddField(
model_name='codebatch',
name='mini_prog_entry_env_version',
field=models.CharField(blank=True, default='release', max_length=128, null=True, verbose_name='小程序入口环境版本(可选), 默认release。如为trial则进入体验版'),
),
]

View File

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

View File

@ -178,6 +178,8 @@ class CodeBatch(models.Model):
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="小程序入口路径(可选)")
mini_prog_entry_env_version = models.CharField(max_length=128, null=True, blank=True, default='release',
verbose_name="小程序入口环境版本(可选), 默认release。如为trial则进入体验版")
def gen_code(self, n):
a = 10 ** (self.num_digits - 1)

View File

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

View File

@ -78,6 +78,7 @@ export default {
'enable_auto_torch',
'camera_sensitivity',
'mini_prog_entry_path',
'mini_prog_entry_env_version',
];
},
visible_fields: function() {
@ -94,6 +95,7 @@ export default {
'scan_redirect_url',
'enable_auto_torch',
'mini_prog_entry_path',
'mini_prog_entry_env_version',
];
},
},