Exemplo n.º 1
0
def get_chat_token(token_type, user_info):
    result = {'code': 1, 'msg': 'ok'}

    nonce = uniqid()
    try:
        if token_type == 1:
            token_id = 'buyer' + limter + str(
                user_info.buyer_id) + limter + user_info.account
        elif token_type == 2:
            token_id = 'shop' + limter + str(
                user_info.shop_id) + limter + user_info.account

        api = ApiClient()
        token = api.call_api(action="/user/getToken",
                             params={
                                 "userId": token_id,
                                 "name": user_info.account,
                                 "portraitUri": "p1"
                             })

        result['token'] = token
    except Exception, e:
        current_app.logger.exception(e)
        result['code'] = 1
        result['msg'] = e.message
Exemplo n.º 2
0
 def setUp(self):
     app_key = os.environ['APP_KEY']
     app_secret = os.environ['APP_SECRET']
     self.client = ApiClient(app_key, app_secret)
Exemplo n.º 3
0
import os
import json
import unittest
import logging

from rong import ApiClient

#app_key = ""
#app_secret = ""

#os.environ.setdefault('rongcloud_app_key', app_key)
#os.environ.setdefault('rongcloud_app_secret', app_secret)

logging.basicConfig(level=logging.INFO)

client = ApiClient()


class ApiTest(unittest.TestCase):
    def test_token_get(self):
        result = client.user_get_token(
            'test-userid1', 'test-name1',
            'http://www.rongcloud.cn/images/logo.png')

        result2 = client.user_get_token(
            'test-userid2', 'test-name2',
            'http://www.rongcloud.cn/images/logo.png')

        self.assertEqual(result[u'code'], 200)
        self.assertEqual(result2[u'code'], 200)
        self.assertEqual(result[u'userId'], 'test-userid1')
Exemplo n.º 4
0
# coding: utf-8

import os
import json
import unittest
import logging
from starmachine import settings

from rong import ApiClient
#您应该将key 和 secret 保存在服务器的环境变量中
os.environ.setdefault('rongcloud_app_key', settings.RONGCLOUD_APP_KEY)
os.environ.setdefault('rongcloud_app_secret', settings.RONGCLOUD_APP_SECRET)

logging.basicConfig(level=logging.INFO)

rong_client = ApiClient(settings.RONGCLOUD_APP_KEY,
                        settings.RONGCLOUD_APP_SECRET)