Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 def get_random_string(self):
     return random_string(16)