Skip to content

Commit 9485274

Browse files
committed
迁移代码
1 parent 7ed3d2e commit 9485274

23 files changed

+737
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5-
5+
.idea
66
# C extensions
77
*.so
88

README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
# python2-sdk
1+
[![API Reference](https://img.shields.io/badge/api-reference-blue.svg)]()
2+
[![Build Status](https://img.shields.io/static/v1?label=build&message=passing&color=32CD32)]()
3+
[![Apache V2 License](https://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/linkv-io/python-sdk/blob/master/LICENSE)
4+
5+
# python2-sdk
6+
7+
LINKV SDK for the Python2 programming language.
8+
9+
## Download
10+
```sh
11+
git clone https://github.com/linkv-io/python2-sdk
12+
```
13+
14+
## Install
15+
```sh
16+
cd python2-sdk
17+
python setup.py build
18+
python setup.py install --record log
19+
```
20+
21+
## Uninstall
22+
```sh
23+
cat log |xargs rm -rf
24+
rm -rf build dist linkv_sdk.egg-info log
25+
```
26+
27+
## Usage
28+
29+
```python
30+
# -*- coding: UTF-8 -*-
31+
32+
from linkv_sdk import linkv_sdk
33+
34+
35+
def main():
36+
app_id = 'rbaiHjNHQyVprPCBSHevvVvuNynNeTvp'
37+
app_secret = '87EA975D424238D0A08F772321169816DD016667D5BB577EBAEB820516698416E4F94C28CB55E9FD8E010260E6C8A177C0B078FC098BCF2E9E7D4A9A71BF1EF8FBE49E05E5FC5A6A35C6550592C1DB96DF83F758EAFBC5B342D5D04C9D92B1A82A76E3756E83A4466DA22635A8A9F88901631B5BBBABC8A94577D66E8B000F4B179DA99BAA5E674E4F793D9E60EEF1C3B757006459ABB5E6315E370461EBC8E6B0A7523CA0032D33B5C0CF83264C9D83517C1C94CAB3F48B8D5062F5569D9793982455277C16F183DAE7B6C271F930A160A6CF07139712A9D3ABF85E05F8721B8BB6CAC1C23980227A1D5F31D23FA6567578AEEB6B124AF8FF76040F9598DDC9DE0DA44EF34BBB01B53E2B4713D2D701A9F913BE56F9F5B9B7D8D2006CA910D8BFA0C34C619AB0EEBDAA474E67115532511686992E88C4E32E86D82736B2FE141E9037381757ED02C7D82CA8FC9245700040D7E1E200029416295D891D388D69AC5197A65121B60D42040393FB42BC2769B1E2F649A7A17083F6AB2B1BE6E993'
38+
39+
if not linkv_sdk.init(app_id, app_secret):
40+
return
41+
42+
live = linkv_sdk.LvLIVE()
43+
44+
third_uid = "test-py-tob"
45+
a_id = "test"
46+
r = live.GetTokenByThirdUID(third_uid, a_id, user_name='test-py',
47+
portrait_uri='http://meet.linkv.sg/app/rank-list/static/img/defaultavatar.cd935fdb.png')
48+
49+
if not r['status']:
50+
print('live.GetTokenByThirdUID(%s)' % r['error'])
51+
return
52+
53+
print('token:%s' % r['live_token'])
54+
live_open_id = r['live_open_id']
55+
r1 = live.GetGoldByLiveOpenID(live_open_id)
56+
if not r1['status']:
57+
print('live.GetGoldByLiveOpenID(%s)' % r1['error'])
58+
return
59+
golds0 = r1['golds']
60+
print('golds0:%d' % golds0)
61+
unique_id = '1231234'
62+
gold = 10
63+
r2 = live.SuccessOrderByLiveOpenID(live_open_id, unique_id, linkv_sdk.OrderTypeAdd, gold, 10, 1,
64+
linkv_sdk.PlatformTypeH5, '')
65+
if not r2['status']:
66+
print('live.SuccessOrderByLiveOpenID(%s)' % r2['error'])
67+
return
68+
69+
golds1 = r2['golds']
70+
print('golds1:%d' % golds1)
71+
if (gold + golds0) != golds1:
72+
print('(golds0+gold) != golds1')
73+
return
74+
75+
unique_id1 = '456456'
76+
ok = live.ChangeGoldByLiveOpenID(live_open_id, unique_id1, linkv_sdk.OrderTypeDel, gold, 1, 'test del')
77+
if not ok:
78+
print('!ok')
79+
return
80+
81+
r3 = live.GetGoldByLiveOpenID(live_open_id)
82+
if not r3['status']:
83+
print('live.GetGoldByLiveOpenID(%s)' % r3['error'])
84+
return
85+
golds2 = r3['golds']
86+
print('golds2:%d' % golds2)
87+
88+
if golds0 != golds2:
89+
print('golds0 != golds2')
90+
91+
print('success')
92+
93+
94+
if __name__ == "__main__":
95+
main()
96+
```
97+
98+
## License
99+
100+
This SDK is distributed under the
101+
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0),
102+
see LICENSE.txt and NOTICE.txt for more information.

example/example.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
from linkv_sdk import linkv_sdk
4+
5+
6+
def main():
7+
app_id = 'rbaiHjNHQyVprPCBSHevvVvuNynNeTvp'
8+
app_secret = '87EA975D424238D0A08F772321169816DD016667D5BB577EBAEB820516698416E4F94C28CB55E9FD8E010260E6C8A177C0B078FC098BCF2E9E7D4A9A71BF1EF8FBE49E05E5FC5A6A35C6550592C1DB96DF83F758EAFBC5B342D5D04C9D92B1A82A76E3756E83A4466DA22635A8A9F88901631B5BBBABC8A94577D66E8B000F4B179DA99BAA5E674E4F793D9E60EEF1C3B757006459ABB5E6315E370461EBC8E6B0A7523CA0032D33B5C0CF83264C9D83517C1C94CAB3F48B8D5062F5569D9793982455277C16F183DAE7B6C271F930A160A6CF07139712A9D3ABF85E05F8721B8BB6CAC1C23980227A1D5F31D23FA6567578AEEB6B124AF8FF76040F9598DDC9DE0DA44EF34BBB01B53E2B4713D2D701A9F913BE56F9F5B9B7D8D2006CA910D8BFA0C34C619AB0EEBDAA474E67115532511686992E88C4E32E86D82736B2FE141E9037381757ED02C7D82CA8FC9245700040D7E1E200029416295D891D388D69AC5197A65121B60D42040393FB42BC2769B1E2F649A7A17083F6AB2B1BE6E993'
9+
10+
if not linkv_sdk.init(app_id, app_secret):
11+
return
12+
13+
live = linkv_sdk.LvLIVE()
14+
15+
third_uid = "test-py-tob"
16+
a_id = "test"
17+
r = live.GetTokenByThirdUID(third_uid, a_id, user_name='test-py',
18+
portrait_uri='http://meet.linkv.sg/app/rank-list/static/img/defaultavatar.cd935fdb.png')
19+
20+
if not r['status']:
21+
print('live.GetTokenByThirdUID(%s)' % r['error'])
22+
return
23+
24+
print('token:%s' % r['live_token'])
25+
live_open_id = r['live_open_id']
26+
r1 = live.GetGoldByLiveOpenID(live_open_id)
27+
if not r1['status']:
28+
print('live.GetGoldByLiveOpenID(%s)' % r1['error'])
29+
return
30+
golds0 = r1['golds']
31+
print('golds0:%d' % golds0)
32+
unique_id = '123123123'
33+
gold = 10
34+
r2 = live.SuccessOrderByLiveOpenID(live_open_id, unique_id, linkv_sdk.OrderTypeAdd, gold, 10, 1,
35+
linkv_sdk.PlatformTypeH5, '')
36+
if not r2['status']:
37+
print('live.SuccessOrderByLiveOpenID(%s)' % r2['error'])
38+
return
39+
40+
golds1 = r2['golds']
41+
print('golds1:%d' % golds1)
42+
if (gold + golds0) != golds1:
43+
print('(golds0+gold) != golds1')
44+
return
45+
46+
unique_id1 = '456456456'
47+
ok = live.ChangeGoldByLiveOpenID(live_open_id, unique_id1, linkv_sdk.OrderTypeDel, gold, 1, 'test del')
48+
if not ok:
49+
print('!ok')
50+
return
51+
52+
r3 = live.GetGoldByLiveOpenID(live_open_id)
53+
if not r3['status']:
54+
print('live.GetGoldByLiveOpenID(%s)' % r3['error'])
55+
return
56+
golds2 = r3['golds']
57+
print('golds2:%d' % golds2)
58+
59+
if golds0 != golds2:
60+
print('golds0 != golds2')
61+
62+
print('success')
63+
64+
65+
if __name__ == "__main__":
66+
main()

linkv_sdk/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: UTF-8 -*-
2+
"""
3+
LINKV SDK for the Python programming language.
4+
"""
5+
6+
__version__ = '0.4.3'
7+
__licence__ = 'Apache-2.0 License'
8+
__doc__ = 'LINKV SDK for the Python programming language.'
9+
__all__ = ['linkv_sdk']

linkv_sdk/__main__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: UTF-8 -*-
2+
from json import dumps
3+
4+
import linkv_sdk
5+
6+
7+
def main():
8+
app_id = 'qOPBZYGqnqgCSJCobhLFRtvvJzeLLzDR'
9+
app_secret = '1EE940FB2E0AB99368DDEF4A7446A17E3418CE9B1721464624A504BBD977A4FC1477F6A1A02B22AF64070A49C32E05B1AC23E47D86BF6C490D637A42735E6DF7589D5644B3DF1BCD489186940ADE4C3D61C6028FCAF90D57FDCA7BA1888DD4B060B2996BCF41087A8CDEE52D775548166FC92B83D88125434597B9394AC3F7C81C9B8A41C0191B0A09AD59F20881A087574C51B0288A1867D8B7EE9CABC97C322F6469E4E19261C7A26527CD65299A564B319F42DB70E016537A5AFAAE896BEE'
10+
11+
if not linkv_sdk.init(app_id, app_secret):
12+
return
13+
14+
print(dumps(obj=linkv_sdk.im().cfg.__dict__, ensure_ascii=False))
15+
print(dumps(obj=linkv_sdk.rtc().cfg.__dict__, ensure_ascii=False))
16+
17+
18+
if __name__ == "__main__":
19+
main()

linkv_sdk/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: UTF-8 -*-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: UTF-8 -*-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
from ffi import dlopen_platform_specific, download
4+
from ctypes import c_char_p, c_void_p, cast
5+
6+
VERSION = '0.0.4'
7+
FILE = 'decrypt'
8+
9+
10+
class _Binding:
11+
core = None
12+
13+
def __init__(self):
14+
self.core = dlopen_platform_specific(FILE, '')
15+
16+
def decrypt(self, app_id, app_secret):
17+
self.core.decrypt.argtypes = [c_char_p, c_char_p]
18+
self.core.decrypt.restype = c_void_p
19+
ptr = self.core.decrypt(app_id.encode('utf-8'), app_secret.encode('utf-8'))
20+
app_config = cast(ptr, c_char_p).value
21+
self.core.release.argtypes = c_void_p,
22+
self.core.release.restype = None
23+
self.core.release(ptr)
24+
return app_config
25+
26+
27+
def download_library():
28+
return download(FILE, "", VERSION)
29+
30+
31+
_binding = None
32+
33+
34+
def binding():
35+
global _binding
36+
if _binding:
37+
return _binding
38+
_binding = _Binding()
39+
return _binding

linkv_sdk/config/bindings/ffi.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
import platform
4+
import os
5+
from requests import get
6+
from tempfile import gettempdir
7+
from ctypes import CDLL
8+
9+
10+
def _platform_file(name):
11+
ext = ''
12+
13+
if platform.uname()[0] == "Linux":
14+
ext = 'so'
15+
elif platform.uname()[0] == "Darwin":
16+
ext = 'dylib'
17+
elif platform.uname()[0] == "Windows":
18+
ext = 'dll'
19+
20+
return "lib{}.{}".format(name, ext)
21+
22+
23+
def dlopen_platform_specific(name, path):
24+
return CDLL('{}/{}'.format(gettempdir() if path == "" else path, _platform_file(name)))
25+
26+
27+
DownloadURL = 'http://dl.linkv.fun/static/server'
28+
29+
30+
def download(name, path, version):
31+
filepath = '{}/{}'.format(gettempdir() if path == "" else path, _platform_file(name))
32+
if os.path.exists(filepath):
33+
return True
34+
35+
r = get('{}/{}/{}'.format(DownloadURL, version, _platform_file(name)))
36+
37+
if r.status_code != 200:
38+
return False
39+
40+
with open(filepath, 'wb') as f:
41+
f.write(r.content)
42+
43+
r.close()
44+
return True

linkv_sdk/config/config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
from linkv_sdk.im.config import dict_config as dict_im_config
4+
from linkv_sdk.rtc.config import dict_config as dict_rtc_config
5+
from linkv_sdk.live.config import dict_config as dict_live_config
6+
from linkv_sdk.http.http import http
7+
from bindings.binding import download_library, binding
8+
from json import loads
9+
10+
11+
def init(app_id, app_secret, version):
12+
http(version)
13+
if not download_library():
14+
return False
15+
json_data = binding().decrypt(app_id, app_secret)
16+
d = loads(json_data)
17+
dict_im_config(d['im'] if 'im' in d.keys() else {})
18+
dict_rtc_config(d['rtc'] if 'rtc' in d.keys() else {})
19+
dict_live_config(d['sensor'] if 'sensor' in d.keys() else {})
20+
21+
return True

0 commit comments

Comments
 (0)