__init__.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:django-shopify-webhook 作者: discolabs 项目源码 文件源码
def post_shopify_webhook(self, topic = None, domain = None, data = None, headers = None, send_hmac = True):
        """
        Simulate a webhook being sent to the application's webhook endpoint with the provided parameters.
        """
        # Set defaults.
        domain = 'test.myshopify.com' if domain is None else domain
        data = {} if data is None else data
        headers = {} if headers is None else headers

        # Dump data as a JSON string.
        data = json.dumps(data)

        # Add required headers.
        headers['HTTP_X_SHOPIFY_TEST'] = 'true'
        headers['HTTP_X_SHOPIFY_SHOP_DOMAIN'] = domain

        # Add optional headers.
        if topic:
            headers['HTTP_X_SHOPIFY_TOPIC'] = topic
        if send_hmac:
            headers['HTTP_X_SHOPIFY_HMAC_SHA256'] = six.text_type(get_hmac(six.b(data), settings.SHOPIFY_APP_API_SECRET))

        return self.client.post(self.webhook_url, data = data, content_type = 'application/json', **headers)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号