def _encrypt_message(self, msg, nonce=None, timestamp=None, crypto_class=None): timestamp = timestamp or int(time.time() * 1000) timestamp = to_text(timestamp) if nonce is None: nonce = random_string() assert self.key is not None pc = crypto_class(self.key) encrypt = to_text(pc.encrypt(msg, self._id)) signature = _get_signature(self.token, timestamp, nonce, encrypt) result = dict() result['msg_signature'] = signature result['encrypt'] = encrypt result['timeStamp'] = timestamp result['nonce'] = nonce return result
def get_jsapi_params(self, url, noncestr=None, timestamp=None): if not noncestr: noncestr = random_string() if timestamp is None: timestamp = int(time.time() * 1000) data = [ 'noncestr={noncestr}'.format(noncestr=noncestr), 'jsapi_ticket={ticket}'.format(ticket=self.jsapi_ticket), 'timestamp={timestamp}'.format(timestamp=timestamp), 'url={url}'.format(url=url), ] signer = DingTalkSigner(delimiter=b'&') signer.add_data(*data) ret = { 'corpId': self.corp_id, 'timeStamp': timestamp, 'nonceStr': noncestr, 'signature': signer.signature } return ret
def get_random_string(self): return random_string(16)