<s> import requests <EOL> from django . utils . http import urlencode <EOL> from allauth . socialaccount . providers . oauth2 . client import OAuth2Error <EOL> from allauth . socialaccount . providers . oauth2 . client import OAuth2Client <EOL> from allauth . compat import OrderedDict <EOL> class WeixinOAuth2Client ( OAuth2Client ) : <EOL> def get_redirect_url ( self , authorization_url , extra_params ) : <EOL> params = { <EOL> '<STR_LIT>' : self . consumer_key , <EOL> '<STR_LIT>' : self . callback_url , <EOL> '<STR_LIT>' : self . scope , <EOL> '<STR_LIT>' : '<STR_LIT:code>' <EOL> } <EOL> if self . state : <EOL> params [ '<STR_LIT:state>' ] = self . state <EOL> params . update ( extra_params ) <EOL> sorted_params = OrderedDict ( ) <EOL> for param in sorted ( params ) : <EOL> sorted_params [ param ] = params [ param ] <EOL> return '<STR_LIT>' % ( authorization_url , urlencode ( sorted_params ) ) <EOL> def get_access_token ( self , code ) : <EOL> data = { '<STR_LIT>' : self . consumer_key , <EOL> '<STR_LIT>' : self . callback_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . consumer_secret , <EOL> '<STR_LIT>' : self . scope , <EOL> '<STR_LIT:code>' : code } <EOL> params = None <EOL> self . _strip_empty_keys ( data ) <EOL> url = self . access_token_url <EOL> if self . access_token_method == '<STR_LIT:GET>' : <EOL> params = data <EOL> data = None <EOL> resp = requests . request ( self . access_token_method , <EOL> url , <EOL> params = params , <EOL> data = data ) <EOL> access_token = None <EOL> if resp . status_code == <NUM_LIT:200> : <EOL> access_token = resp . json ( ) <EOL> if not access_token or '<STR_LIT>' not in access_token : <EOL> raise OAuth2Error ( '<STR_LIT>' <EOL> % resp . content ) <EOL> return access_token </s>
