Best Python code snippet using Kiwi_python
jsapi.py
Source:jsapi.py
...27 'nonceStr': nonce_str or get_random_string(32),28 'signType': 'MD5',29 'package': 'prepay_id={0}'.format(prepay_id),30 }31 return calculate_signature(32 data,33 self._client.api_key if not self._client.debug else self._client.debug_api_key34 )35 def get_jsapi_params(self, prepay_id, timestamp=None, nonce_str=None, jssdk=False):36 """è·å JSAPI åæ°37 Parameters38 ----------39 prepay_id : string40 ç»ä¸ä¸åæ¥å£è¿åç prepay_id åæ°å¼41 timestamp: string42 æ¶é´æ³ï¼é»è®¤ä¸ºå½åæ¶é´æ³43 nonce_str: string44 éæºå符串ï¼é»è®¤èªå¨çæ45 jssdk: bool46 å端è°ç¨æ¹å¼ï¼é»è®¤ä½¿ç¨ WeixinJSBridge47 ä½¿ç¨ jssdk è°èµ·æ¯ä»çè¯ï¼timestamp ç s 为å°å48 ä½¿ç¨ WeixinJSBridge è°èµ·æ¯ä»çè¯ï¼timeStamp ç S 为大å49 Returns50 -------51 dict52 """53 data = {54 "appId": self.app_id,55 "timeStamp": timestamp or text_type(int(time.time())),56 "nonceStr": nonce_str or get_random_string(32),57 "signType": "MD5",58 "package": "prepay_id={0}".format(prepay_id)59 }60 sign = calculate_signature(61 data,62 self._client.api_key if not self._client.debug else self._client.debug_api_key63 )64 data['paySign'] = sign.upper()65 if jssdk:66 data['timestamp'] = data.pop('timeStamp')...
sign.py
Source:sign.py
...11 data += to_binary('{0}'.format(api_key))12 return data13# Toutiao Relative Signature Algorithm14# See: https://developer.toutiao.com/docs/payment/#%E7%AD%BE%E5%90%8D%E8%AF%B4%E6%98%8E15def calculate_signature(params, api_key):16 url = format_url(params, api_key)17 return to_text(hashlib.md5(url).hexdigest())18def check_signature(params, api_key, sign=None):19 _params = copy.deepcopy(params)20 sign = sign or _params.pop('sign', '')21 return sign == calculate_signature(_params, api_key)22def fill_signature(params, api_key):23 sign = calculate_signature(params, api_key)24 params['sign'] = sign25 return params26def calculate_requestPayment_signature(params, api_key):27 return calculate_signature({28 'app_id': params.get('app_id'),29 'sign_type': 'MD5',30 'timestamp': params.get('timestamp'),31 'trade_no': params.get('trade_no'),32 'merchant_id': params.get('merchant_id'),33 'uid': params.get('uid'),34 'total_amount': params.get('total_amount'),35 'params': params.get('params'),36 }, api_key)37def check_signature(params, api_key, sign=None):38 _params = copy.deepcopy(params)39 sign = sign or _params.pop('sign', '')40 return sign == calculate_requestPayment_signature(_params, api_key)41def fill_signature(params, api_key):...
lib.py
Source:lib.py
...4import base645import hashlib6import hmac7import json8def calculate_signature(key, msg):9 """10 Calculate HMAC signature for ``msg``, using ``key`` and SHA111 as digest algorithm.12 :param key: The shared key13 :param msg: The message to sign14 :return: The signature, as hexadecimal string15 """16 return hmac.HMAC(key=key, msg=msg, digestmod=hashlib.sha1).hexdigest()17def generate_url(base, key, payload, ext=None):18 """19 Generate URL containing a signed payload.20 """21 payload_str = base64.urlsafe_b64encode(json.dumps(payload))22 if ext is not None:23 payload_str = '{0}.{1}'.format(payload_str, ext)24 signature = calculate_signature(key, payload_str)25 return '{0}/{1}?s={2}'.format(base, payload_str, signature)26def verify_payload(key, payload, signature):27 """28 Verify a signed payload, extracted from a URL29 """30 new_signature = calculate_signature(key, payload)31 if new_signature != signature:32 raise ValueError("Invalid signature")33 # Ignore everything after the dot -- extension is just fancy34 if '.' in payload:35 payload = payload.split('.', 1)[0]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!