• django微信卡劵实例代码


    from django.test import TestCase
    
    # Create your tests here.
    import time
    import random
    import string
    import hashlib
    from django.core import serializers
    from django.http import JsonResponse, HttpResponse, HttpResponseRedirect
    from django.shortcuts import render, redirect
    import uuid, datetime, json, time
    from datetime import timedelta
    from dateutil.relativedelta import relativedelta
    from wechatpy import WeChatClient
    import json, re, urllib3
    import os
    import json
    from wechatpy import WeChatPay
    import time
    import random
    
    # 企业号配置信息
    
    ENV_PROFILE = os.getenv("ENV")
    if ENV_PROFILE == "PRO":
        from fsfhGolf import prd_settings as config
    elif ENV_PROFILE == "TEST":
        from fsfhGolf import test_settings as config
    else:
        from fsfhGolf import settings as config
    
    # Create your views here.
    
    appid = config.weChatConfig["appid"]
    appsecret = config.weChatConfig["appsecret"]
    client = WeChatClient(appid, appsecret)
    domain = config.domain
    proxies = config.proxies
    if ENV_PROFILE == "PRO":
        client._http.proxies.update(proxies)
    
    endTime = (datetime.datetime.now()+datetime.timedelta(days=10)).strftime("%Y-%m-%d %H:%M:%S")
    endTime = time.strptime(endTime, "%Y-%m-%d %H:%M:%S")
    
    end_timestamp =time.mktime(endTime)
    print(end_timestamp)
    card_data = {
      "card": {
          "card_type": "GROUPON",
          "groupon": {
              "base_info": {
                  "logo_url":"http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0",
                  "brand_name": "微信餐厅",
                  "code_type": "CODE_TYPE_TEXT",
                  "title": "132元双人火锅套餐",
                  "color": "Color010",
                  "notice": "使用时向服务员出示此券",
                  "service_phone": "020-88888888",
                  "description": "不可与其他优惠同享
    如需团购券发票,请在消费时向商户提出
    店内均可使用,仅限堂食",
                  "date_info": {
                      "type": "DATE_TYPE_FIX_TIME_RANGE",
                      "begin_timestamp":int(time.time()),
                      "end_timestamp": int(end_timestamp)
                  },
                  "sku": {
                      "quantity": 500000
                  },
                  "use_limit":100,
                  "get_limit": 3,
                  "use_custom_code": False,
                  "bind_openid": False,
                  "can_share": True,
                  "can_give_friend": True,
                  "location_id_list": [
                  ],
                  "center_title": "顶部居中按钮",
                  "center_sub_title": "按钮下方的wording",
                  "custom_url_name": "立即使用",
                  "custom_url_sub_title": "6个汉字tips",
                  "promotion_url_name": "更多优惠",
                  "source": "大众点评"
              },
               "advanced_info": {
                   "use_condition": {
                       "accept_category": "鞋类",
                       "reject_category": "阿迪达斯",
                       "can_use_with_other_discount": True
                   },
                   "abstract": {
                       "abstract": "微信餐厅推出多种新季菜品,期待您的光临",
                       "icon_url_list": [
                           "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0"
                       ]
                   },
                   "text_image_list": [
                       {
                           "image_url": "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
                           "text": "此菜品精选食材,以独特的烹饪方法,最大程度地刺激食 客的味蕾"
                       },
                       {
                           "image_url": "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sj piby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
                           "text": "此菜品迎合大众口味,老少皆宜,营养均衡"
                       }
                   ],
                   "time_limit": [
                       {
                           "type": "MONDAY",
                           "begin_hour":0,
                           "end_hour":10,
                           "begin_minute":10,
                           "end_minute":59
                       },
                       {
                           "type": "HOLIDAY"
                       }
                   ],
                   "business_service": [
                       "BIZ_SERVICE_FREE_WIFI",
                       "BIZ_SERVICE_WITH_PET",
                       "BIZ_SERVICE_FREE_PARK",
                       "BIZ_SERVICE_DELIVER"
                   ]
               },
              "deal_detail": "以下锅底2选1(有菌王锅、麻辣锅、大骨锅、番茄锅、清补 凉锅、酸菜鱼锅可选):
    大锅1份 12元
    小锅2份 16元 "
          }
      }}
    
    
    result = client.card.create(card_data)
    print(result)

    返回结果

     参考实例:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#4

          https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Create_a_Coupon_Voucher_or_Card.html#1

  • 相关阅读:
    利用async和await异步操作解决node.js里面fs模块异步读写,同步结果的问题
    node.js的fs核心模块读写文件操作 -----由浅入深
    node.js 发布订阅模式
    js 发布订阅模式
    vue.js定义一个一级的路由 ----由浅入深
    vue.js编程式路由导航 --- 由浅入深
    vue.js嵌套路由-------由浅入深
    Spring事件体系
    Hibernate监听器
    学习网站地址
  • 原文地址:https://www.cnblogs.com/wangcongxing/p/12456553.html
Copyright © 2020-2023  润新知