|  |  | @@ -45,6 +45,7 @@ def DJANGO_WE_MESSAGE_CALLBACK_FUNC(request, data, decrypted=None): | 
            
            
              | 45 | 45 |  def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None): | 
            
            
              | 46 | 46 |      """ WeChat Component Message Callback Func """ | 
            
            
              | 47 | 47 |      from account.models import UserInfo | 
            
            
              |  | 48 | +    from django_we.models import SubscribeUserInfo | 
            
            
              | 48 | 49 |      from utils.redis.connect import r | 
            
            
              | 49 | 50 |      from utils.redis.rkeys import SUBSCRIBE_USERINFO_LIST, MEMBERCARD_USERINFO_LIST | 
            
            
              | 50 | 51 |   | 
            
            
            
            
              |  |  | @@ -78,7 +79,7 @@ def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None): | 
            
            
              | 78 | 79 |              }) | 
            
            
              | 79 | 80 |   | 
            
            
              | 80 | 81 |      # WINE | 
            
            
              | 81 |  | -    if tousername == 'gh_2e5f21d2a57d': | 
            
            
              |  | 82 | +    elif tousername == 'gh_2e5f21d2a57d': | 
            
            
              | 82 | 83 |          brand_id = settings.COMPONENT_CALLBACK_CONFIG[tousername] | 
            
            
              | 83 | 84 |          if event == 'user_get_card': | 
            
            
              | 84 | 85 |              UserInfo.objects.using('wine').filter(unionid=unionid).update(openid=openid, has_membercard=True, membercardid=membercardid, memberusercardcode=memberusercardcode) | 
            
            
            
            
              |  |  | @@ -96,7 +97,7 @@ def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None): | 
            
            
              | 96 | 97 |              }) | 
            
            
              | 97 | 98 |   | 
            
            
              | 98 | 99 |      # 腾龙 | 
            
            
              | 99 |  | -    if tousername == 'gh_c87efc299ce5': | 
            
            
              |  | 100 | +    elif tousername == 'gh_c87efc299ce5': | 
            
            
              | 100 | 101 |          brand_id = settings.COMPONENT_CALLBACK_CONFIG[tousername] | 
            
            
              | 101 | 102 |          if event == 'user_get_card': | 
            
            
              | 102 | 103 |              UserInfo.objects.filter(unionid=unionid).update(openid=openid, has_membercard=True, membercardid=membercardid, memberusercardcode=memberusercardcode) | 
            
            
            
            
              |  |  | @@ -113,6 +114,64 @@ def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None): | 
            
            
              | 113 | 114 |                  'openid': openid, | 
            
            
              | 114 | 115 |              }) | 
            
            
              | 115 | 116 |   | 
            
            
              |  | 117 | +    # 函院 | 
            
            
              |  | 118 | +    elif tousername == 'gh_48cbe3523cf6': | 
            
            
              |  | 119 | +        # OrderedDict([(u'ToUserName', u'gh_48cbe3523cf6'), (u'FromUserName', u'oRgy0uH8qHxzwwSC9H7YrRIv5Mxw'), (u'CreateTime', u'1598886287'), (u'MsgType', u'event'), (u'Event', u'subscribe'), (u'EventKey', u'qrscene_book'), (u'Ticket', u'gQHL8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyYWgwVjRSNmNhUVUxMDAwMHcwNzkAAgT8OkxfAwQAAAAA')]) | 
            
            
              |  | 120 | +        eventkey = decrypted.get('EventKey', '') | 
            
            
              |  | 121 | + | 
            
            
              |  | 122 | +        if event == 'subscribe' or event == 'unsubscribe': | 
            
            
              |  | 123 | +            CFG = settings.WECHAT.get('COMPONENT', {}) | 
            
            
              |  | 124 | + | 
            
            
              |  | 125 | +            appid = 'wx75b14576708d330d' | 
            
            
              |  | 126 | + | 
            
            
              |  | 127 | +            # 获取第三方平台token | 
            
            
              |  | 128 | +            token = authorizer_access_token( | 
            
            
              |  | 129 | +                component_appid=CFG['appID'], | 
            
            
              |  | 130 | +                component_secret=CFG['appsecret'], | 
            
            
              |  | 131 | +                authorizer_appid=appid, | 
            
            
              |  | 132 | +                storage=RedisStorage(r) | 
            
            
              |  | 133 | +            ) | 
            
            
              |  | 134 | + | 
            
            
              |  | 135 | +            # 获取用户信息 | 
            
            
              |  | 136 | +            userinfo = get_user_info(openid, appid=appid, secret=None, token=token, storage=RedisStorage(r)) | 
            
            
              |  | 137 | +            subscribe, unionid, openid = userinfo.get('subscribe', ''), userinfo.get('unionid', ''), userinfo.get('openid', '') | 
            
            
              |  | 138 | + | 
            
            
              |  | 139 | +            # 更新关注信息 | 
            
            
              |  | 140 | +            if subscribe: | 
            
            
              |  | 141 | +                SubscribeUserInfo.objects.using('hanyuan').update_or_create(openid=openid, defaults={ | 
            
            
              |  | 142 | +                    'unionid': unionid, | 
            
            
              |  | 143 | +                    'nickname': userinfo.get('nickname', ''), | 
            
            
              |  | 144 | +                    'sex': userinfo.get('sex', ''), | 
            
            
              |  | 145 | +                    'headimgurl': userinfo.get('headimgurl', ''), | 
            
            
              |  | 146 | +                    'country': userinfo.get('country', ''), | 
            
            
              |  | 147 | +                    'province': userinfo.get('province', ''), | 
            
            
              |  | 148 | +                    'city': userinfo.get('city', ''), | 
            
            
              |  | 149 | +                    'subscribe': userinfo.get('subscribe', ''), | 
            
            
              |  | 150 | +                    'subscribe_time': userinfo.get('subscribe_time', ''), | 
            
            
              |  | 151 | +                    'subscribe_scene': userinfo.get('subscribe_scene', ''), | 
            
            
              |  | 152 | +                    'groupid': userinfo.get('groupid', ''), | 
            
            
              |  | 153 | +                    'tagid_list': userinfo.get('tagid_list', ''), | 
            
            
              |  | 154 | +                    'qr_scene': userinfo.get('qr_scene', ''), | 
            
            
              |  | 155 | +                    'qr_scene_str': userinfo.get('qr_scene_str', ''), | 
            
            
              |  | 156 | +                    'language': userinfo.get('language', ''), | 
            
            
              |  | 157 | +                    'remark': userinfo.get('remark', ''), | 
            
            
              |  | 158 | +                }) | 
            
            
              |  | 159 | +            else: | 
            
            
              |  | 160 | +                SubscribeUserInfo.objects.filter(openid=openid).update(subscribe=subscribe) | 
            
            
              |  | 161 | + | 
            
            
              |  | 162 | +            # 根据场景值判断是否发会员卡 | 
            
            
              |  | 163 | +            if eventkey: | 
            
            
              |  | 164 | +                scene = parse_eventkey(eventkey, event='subscribe') | 
            
            
              |  | 165 | +                if scene: | 
            
            
              |  | 166 | +                    send_custom_card_message( | 
            
            
              |  | 167 | +                        openid=openid, | 
            
            
              |  | 168 | +                        card_id=settings.DJANGO_WE_MEMBER_CARD_ID, | 
            
            
              |  | 169 | +                        appid=appid, | 
            
            
              |  | 170 | +                        secret=None, | 
            
            
              |  | 171 | +                        token=token, | 
            
            
              |  | 172 | +                        storage=RedisStorage(r) | 
            
            
              |  | 173 | +                    ) | 
            
            
              |  | 174 | + | 
            
            
              | 116 | 175 |   | 
            
            
              | 117 | 176 |  def DJANGO_WE_REDIS_OBJ_FUNC(request): | 
            
            
              | 118 | 177 |      """ WeChat Redis Object Callback Func """ |