Example #1
0
    def get_jsapi_ticket(app_id, app_secret):
        """
        获取微信公众号 jsapi_ticket
        :param app_id: 微信公众号应用唯一标识
        :param app_secret: 微信公众号应用密钥(注意保密)
        :return: array 包含 jsapi_ticket 的数组或者错误信息
        """
        data = dict()
        data['appid'] = app_id
        data['secret'] = app_secret
        data['grant_type'] = 'client_credential'
        query_str = urllib.urlencode(data)
        access_token_url = 'https://api.weixin.qq.com/cgi-bin/token?' + query_str
        client = http_client.new_default_http_client()
        rbody, rcode = client.request('GET', access_token_url, {})
        rbody = util.json.loads(rbody)
        if rcode != 200:
            return rbody

        data = dict()
        data['access_token'] = rbody['access_token']
        data['type'] = 'jsapi'
        query_str = urllib.urlencode(data)
        jsapi_ticket_url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?' + query_str
        client = http_client.new_default_http_client()
        rbody, rcode = client.request('GET', jsapi_ticket_url, {})
        data = util.json.loads(rbody)
        if rcode == 200:
            return data
Example #2
0
    def get_jsapi_ticket(app_id, app_secret):
        """
        获取微信公众号 jsapi_ticket
        :param app_id: 微信公众号应用唯一标识
        :param app_secret: 微信公众号应用密钥(注意保密)
        :return: array 包含 jsapi_ticket 的数组或者错误信息
        """
        data = dict()
        data['appid'] = app_id
        data['secret'] = app_secret
        data['grant_type'] = 'client_credential'
        query_str = urllib.urlencode(data)
        access_token_url = 'https://api.weixin.qq.com/cgi-bin/token?' + query_str
        client = http_client.new_default_http_client()
        rbody, rcode = client.request('GET', access_token_url, {})
        rbody = util.json.loads(rbody)
        if rcode != 200:
            return rbody

        data = dict()
        data['access_token'] = rbody['access_token']
        data['type'] = 'jsapi'
        query_str = urllib.urlencode(data)
        jsapi_ticket_url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?' + query_str
        client = http_client.new_default_http_client()
        rbody, rcode = client.request('GET', jsapi_ticket_url, {})
        data = util.json.loads(rbody)
        if rcode == 200:
            return data
Example #3
0
    def __init__(self, key=None, client=None):
        self.api_key = key

        from pingpp import verify_ssl_certs

        self._client = client or http_client.new_default_http_client(
            verify_ssl_certs=verify_ssl_certs)
    def __init__(self, key=None, client=None):
        self.api_key = key

        from pingpp import verify_ssl_certs

        self._client = client or http_client.new_default_http_client(
            verify_ssl_certs=verify_ssl_certs)
Example #5
0
    def get_jsapi_ticket(app_id, app_secret):
        """
        获取微信公众号 jsapi_ticket
        :param app_id: 微信公众号应用唯一标识
        :param app_secret: 微信公众号应用密钥(注意保密)
        :return: array 包含 jsapi_ticket 的数组或者错误信息
        """
        data = dict()
        data['appid'] = app_id
        data['secret'] = app_secret
        data['grant_type'] = 'client_credential'
        query_str = urlencode(data)
        access_token_url = \
            'https://api.weixin.qq.com/cgi-bin/token?' + query_str
        client = http_client.new_default_http_client(verify_ssl_certs=verify,
                                                     proxy=proxy,
                                                     ca_bundle=ca_bundle)
        rbody, rcode, headers = client.request('GET', access_token_url, {})
        if hasattr(rbody, 'decode'):
            rbody = rbody.decode('utf-8')
        rbody = util.json.loads(rbody)
        if rcode != 200:
            return rbody

        if 'access_token' not in rbody:
            return None

        data = dict()
        data['access_token'] = rbody['access_token']
        data['type'] = 'jsapi'
        query_str = urlencode(data)
        jsapi_ticket_url = \
            'https://api.weixin.qq.com/cgi-bin/ticket/getticket?' + query_str
        client = http_client.new_default_http_client(verify_ssl_certs=verify,
                                                     proxy=proxy,
                                                     ca_bundle=ca_bundle)
        rbody, rcode, headers = client.request('GET', jsapi_ticket_url, {})
        if hasattr(rbody, 'decode'):
            rbody = rbody.decode('utf-8')
        data = util.json.loads(rbody)
        if rcode == 200:
            return data

        return None
    def __init__(self, key=None, client=None, api_base=None, api_version=None):
        self.api_base = api_base or pingpp.api_base
        self.api_key = key
        self.api_version = api_version or pingpp.api_version

        from pingpp import verify_ssl_certs as verify
        from pingpp import proxy
        from pingpp import ca_bundle

        self._client = client or http_client.new_default_http_client(
            verify_ssl_certs=verify, proxy=proxy, ca_bundle=ca_bundle)
Example #7
0
    def get_openid(app_id, app_secret, code):
        """
        获取微信公众号授权用户唯一标识
        :param app_id: 微信公众号应用唯一标识
        :param app_secret: 微信公众号应用密钥(注意保密)
        :param code: 授权code, 通过调用WxpubOAuth.createOauthUrlForCode来获取
        :return: openid 微信公众号授权用户唯一标识, 可用于微信网页内支付
        """
        url = WxpubOauth.create_oauth_url_for_openid(app_id, app_secret, code)
        client = http_client.new_default_http_client()
        rbody, rcode = client.request('GET', url, {})
        if rcode == 200:
            data = util.json.loads(rbody)
            return data['openid']

        return None
Example #8
0
    def get_openid(app_id, app_secret, code):
        """
        获取微信公众号授权用户唯一标识
        :param app_id: 微信公众号应用唯一标识
        :param app_secret: 微信公众号应用密钥(注意保密)
        :param code: 授权code, 通过调用WxpubOAuth.createOauthUrlForCode来获取
        :return: openid 微信公众号授权用户唯一标识, 可用于微信网页内支付
        """
        url = WxpubOauth.create_oauth_url_for_openid(app_id, app_secret, code)
        client = http_client.new_default_http_client()
        rbody, rcode = client.request('GET', url, {})
        if rcode == 200:
            data = util.json.loads(rbody)
            return data['openid']

        return None
Example #9
0
    def get_openid(app_id, app_secret, code):
        """
        获取微信公众号授权用户唯一标识
        :param app_id: 微信公众号应用唯一标识
        :param app_secret: 微信公众号应用密钥(注意保密)
        :param code: 授权code, 通过调用WxpubOAuth.createOauthUrlForCode来获取
        :return: openid 微信公众号授权用户唯一标识, 可用于微信网页内支付
        """
        url = WxpubOauth.create_oauth_url_for_openid(app_id, app_secret, code)
        client = http_client.new_default_http_client(
            verify_ssl_certs=verify, proxy=proxy, ca_bundle=ca_bundle)
        rbody, rcode, headers = client.request('GET', url, {})
        if rcode == 200:
            if hasattr(rbody, 'decode'):
                rbody = rbody.decode('utf-8')
            data = util.json.loads(rbody)
            if 'openid' in data:
                return data['openid']

        return None