代码拿去,有更新,意见提示与我,互补,谢谢
import time
from django.core.cache import cache
import requests
import hashlib
import random
import string
class wxJdkParmasView(object):
''' 1, 此处官方文档明确提到用户需要缓存jsapi_ticket
因为其api调用次数非常有限,根据文档说明我把获取基础支持的acess_token和ticket写到了一起
2, 此类是给前端js_JDK构造参数,并得到 nonceStr,signature,timestamp 的类,调用signutareEncryption()即可
Redis缓存,需要自己配置,网上一大堆,此就不说了
3, signature生成需要一下几个参数noncestr(随机字符串),
有效的jsapi_ticket, timestamp(时间戳),
url(当前网页的URL,不包含#及其后面部分)
'''
def __init__(self,url):
self.app_id = "自己的APP_ID"
self.app_secret = "自己的获取Token的随机字符串"
self.base_get_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s'%(self.app_id,self.app_secret)
self.get_ticket_url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={}&type=jsapi'
self.ret = {
'nonceStr': self<