def __init__(self, on_message, on_open=None, on_error=None, on_close=None, on_data=None): mixin_api = MIXIN_API(mixin_config) encoded = mixin_api.genGETJwtToken('/', "", str(uuid.uuid4())) if on_open is None: on_open = MIXIN_WS_API.__on_open if on_close is None: on_close = MIXIN_WS_API.__on_close if on_error is None: on_error = MIXIN_WS_API.__on_error if on_data is None: on_data = MIXIN_WS_API.__on_data self.ws = websocket.WebSocketApp( "wss://blaze.mixin.one/", on_message=on_message, on_error=on_error, on_close=on_close, header=["Authorization:Bearer " + encoded.decode()], subprotocols=["Mixin-Blaze-1"], on_data=on_data) self.ws.on_open = on_open
def freetoken(): if (request.is_json): content = request.get_json() print(content) if (('session_secret' in content) and ('full_name' in content)): print (content['session_secret']) mixinApiBotInstance = MIXIN_API(mixin_config) body_in_json = json.dumps(content) token = mixinApiBotInstance.genPOSTJwtToken("/users", body_in_json, str(uuid.uuid4()), 20).decode('utf8') return jsonify({"token":token}) return "OK"
def generateMixinAPI(private_key,pin_token,session_id,user_id,pin,client_secret): mixin_config.private_key = private_key mixin_config.pin_token = pin_token mixin_config.pay_session_id = session_id mixin_config.client_id = user_id mixin_config.client_secret = client_secret mixin_config.pay_pin = pin return MIXIN_API(mixin_config)
from flask import Flask, redirect, request import requests import json import mixin_config from mixin_api import MIXIN_API mixin_api = MIXIN_API(mixin_config) # 启动 Flask app = Flask(__name__) @app.route('/') def index(): # 1. 获得用户的授权 Request Authorization Code scope = 'PROFILE:READ+PHONE:READ+CONTACTS:READ+ASSETS:READ' get_auth_code_url = 'https://mixin.one/oauth/authorize?client_id=' + mixin_config.client_id + '&scope=' + scope + '&response_type=code' return redirect(get_auth_code_url) @app.route('/user') def user(): # 2. 取得 Authorization Token auth_token = get_auth_token() data = mixin_api.getMyProfile(auth_token)
from Crypto.PublicKey import RSA from mixin_api import MIXIN_API # from random_word import RandomWords import mixin_config import json def pubkeyContent(inputContent): contentWithoutHeader = inputContent[len("-----BEGIN PUBLIC KEY-----") + 1:] contentWithoutTail = contentWithoutHeader[:-1 * ( len("-----END PUBLIC KEY-----") + 1)] contentWithoutReturn = contentWithoutTail[:64] + contentWithoutTail[ 65:129] + contentWithoutTail[130:194] + contentWithoutTail[195:] return contentWithoutReturn mixin_api = MIXIN_API(mixin_config) key = RSA.generate(1024) pubkey = key.publickey() print(key.exportKey()) print(pubkey.exportKey()) private_key = key.exportKey() session_key = pubkeyContent(pubkey.exportKey()) # print(session_key) print(session_key.decode()) userInfo = mixin_api.createUser(session_key.decode(), "Tom Bot") print(userInfo) # r = RandomWords() # r.get_random_word()
}) print(r.status_code) if r.status_code != 200: error_body = result_obj['error'] print(error_body) r.raise_for_status() result_obj = r.json() print(result_obj) userInfo = result_obj["data"] user_uuid = userInfo["user_id"] return user_uuid mixin_api_robot = MIXIN_API() mixin_api_robot.appid = mixin_config.mixin_client_id mixin_api_robot.secret = mixin_config.mixin_client_secret mixin_api_robot.sessionid = mixin_config.mixin_pay_sessionid mixin_api_robot.private_key = mixin_config.private_key mixin_api_robot.asset_pin = mixin_config.mixin_pay_pin mixin_api_robot.pin_token = mixin_config.mixin_pin_token #http://travistidwell.com/jsencrypt/demo/ private_key = """-----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDnfy/s9NjXQK3knnsr9+vuB1XQQUeKoWCFcEBO7iD4KRbJ2mwC Bx92iOEVpaVMxS2bykbczXGnnG6NnQBwPx4cx3Z+N/ibG+YkDakAg1F00D9JvPcb oRFy/GRAvtm+dj3GBa74c1S1J4XbXq5H1nqlraZh/hrhCs3pV+H2ooCUpQIDAQAB AoGAB2zG5ry7r7u9WBXVMYXUJWBK2lEdsE6Yv+7nwSBWIl9/AZ5l1HLSCYU+Yulb MekpG1QTjcVxHcUgrp4Yg4EiwA3tNuSTnjomph696HaA04aX7JRWpJX7lPNIbBGL 2QUkOo5uoyrvqAgLJq4dvcpWBzOwI/yJACS4kqMukjY3jUECQQD8qLb+g8Ar/Ezp 70/dYkcdEDbT8p6XlEAI8R3X+L5itcgDl6RMinPXIzXcRIGTZzoTeFXZzvr3XC+6
def getAuthToken(self): mixin_api = MIXIN_API(robot_config) authToken = mixin_api.genGETJwtToken('/', "", str(uuid.uuid4())) return authToken
# Create all tables in the engine. This is equivalent to "Create Table" # statements in raw SQL. Base.metadata.create_all(engine) Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) # A DBSession() instance establishes all conversations with the database # and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() mixin_api_robot = MIXIN_API() mixin_api_robot.appid = mixin_config.mixin_client_id mixin_api_robot.secret = mixin_config.mixin_client_secret mixin_api_robot.sessionid = mixin_config.mixin_pay_sessionid mixin_api_robot.private_key = mixin_config.private_key mixin_api_robot.asset_pin = mixin_config.mixin_pay_pin mixin_api_robot.pin_token = mixin_config.mixin_pin_token freeBonusTimeTable = {} def writeMessage(websocketInstance, action, params): Message = {"id": str(uuid.uuid1()), "action": action, "params": params} Message_instring = json.dumps(Message) fgz = StringIO() gzip_obj = gzip.GzipFile(mode='wb', fileobj=fgz)
Mixin API TEST for Python 3.x Base on: https://github.com/includeleec/mixin-python3-sdk, Author: leec env: python 3.x Modified by mosjin Website: jinLab.com mixin: 1051676 update: 2020-02-14 """ from mixin_api import MIXIN_API from config import robot_config import time from config import mixin_asset_lists mixin_api = MIXIN_API(robot_config) transfer2user_id = 'b33b8e1a-ac41-40f4-8172-1fb5591f0895' # mosjin user id # cuiniubi token asset id #test robot transfer to user_id for i in range(1, 5): r = mixin_api.transferTo(transfer2user_id, mixin_asset_lists.CNB_ASSET_ID, i /10000, "转账次数:" + str(i)) time.sleep(1) mixin_api.getTransfer('bc52ff5a-f610-11e8-8e2a-28c63ffad907')
Address += prefix + "fee : %s\n"%address_fee Address += prefix + "dust : %s\n"%address_dust return Address def strPresent_of_btc_withdrawaddress(thisAddress, prefix= " " * 8): return strPresent_of_asset_withdrawaddress(thisAddress, BTC_ASSET_ID, prefix) def loadSnapshots(UserInstance, timestamp, asset_id = "", limit = 500): USDT_Snapshots_result_of_account = UserInstance.my_snapshots_after(timestamp, asset_id , limit) for singleSnapShot in USDT_Snapshots_result_of_account: is_exin = exincore_api.about_me(singleSnapShot) if(is_exin): print(is_exin) mixinApiBotInstance = MIXIN_API(mixin_config) padding = 70 PromptMsg = "Read first user from local file new_users.csv : loaduser\n" PromptMsg += "Create account and append to new_users.csv : create\n" PromptMsg += "Exit : q\n" PromptMsg_nolocalfile = "Create account and append to new_users.csv : create\n" PromptMsg_nolocalfile += "Exit : q\n" loadedPromptMsg = "Read account asset non-zero balance".ljust(padding) + ": balance\n" loadedPromptMsg += "deposit asset ".ljust(padding) + ": deposit\n" loadedPromptMsg += "send asset ".ljust(padding) + ": send\n" loadedPromptMsg += "Read transaction of my account".ljust(padding) + ": searchsnapshots\n" loadedPromptMsg += "Read transaction of my account".ljust(padding) + ": searchsnapshot\n" loadedPromptMsg += "Instant exchange BTC, USDT ... : ExinCore ".ljust(padding) + ": instanttrade\n" loadedPromptMsg += "Ocean.one protocol exchange : ocean.one".ljust(padding) + ": ocean\n"
# -*- coding: utf-8 -*- """ Mixin API TEST for Python 3.x env: python 3.x code by lee.c update at 2018.12.2 """ from mixin_api import MIXIN_API import mixin_config import time mixin_api = MIXIN_API(mixin_config) transfer2user_id = 'd33f7efd-4b0b-41ff-baa3-b22ea40eb44f' # my user id # cuiniubi token asset id CNB_ASSET_ID = "965e5c6e-434c-3fa9-b780-c50f43cd955c" # test robot transfer to user_id # for i in range(1, 5): # r = mixin_api.transferTo(transfer2user_id, CNB_ASSET_ID, i, "转账次数:" + str(i)) # time.sleep(1) mixin_api.getTransfer('bc52ff5a-f610-11e8-8e2a-28c63ffad907') # mixin_api.getTransfer('13f4c4de-f572-11e8-94cc-00e04c6aa167') # #
"") btcInfo = mixinApiNewUserInstance.getAsset(asset_id) print(btcInfo) if isBTC: print("Account %s \'s Bitcoin wallet address is %s " % (userid, btcInfo.get("data").get("public_key"))) else: print( "Account %s \'s EOS account name is %s, wallet address is %s " % (userid, btcInfo.get("data").get("account_name"), btcInfo.get("data").get("account_tag"))) # print(btcInfo.get("data").get("public_key")) mixinApiBotInstance = MIXIN_API(mixin_config) PromptMsg = "1: Create user and update PIN\n2: Read Bitcoin balance \n3: Read Bitcoin Address\n4: Read EOS balance\n" PromptMsg += "5: Read EOS address\n6: Transfer Bitcoin from bot to new account\n7: Transfer Bitcoin from new account to Master\n" PromptMsg += "8: Withdraw bot's Bitcoin\n9: Withdraw bot's EOS\na: Verify Pin\nd: Create Address and Delete it\nr: Create Address and read it\n" PromptMsg += "gensnap: Generate snapshot for one of my snapshot\n" PromptMsg += "q: Exit \nMake your choose:" while (1 > 0): cmd = input(PromptMsg) if (cmd == 'q'): exit() print("Run...") if (cmd == 'gensnap'): snapshot_id = input("snapshot id:") snapshot = mixinApiBotInstance.account_snapshot_prove(snapshot_id) print("snapshot information start:")
return if 'p' == realData: myPrint('you need to pay') money = random.randint( 5, 23 ) / 100000 toPay = "打赏作者: {}".format( money ) MIXIN_WS_API.sendUserPayAppButton(ws, conversationId, userId, "打赏机器人", mixin_asset_lists.CNB_ASSET_ID, money, userId ) return if 't' == realData: # 机器人 转给 userId myPrint('transfer to you') myPrint( "userId: %s, jinId: %s" % ( userId, get_admin_mixin_id() ) ) money = random.randint( 1, 5 ) / 100000 mxUuid = "mixin://users/{}".format( robot_config.client_id ) mixin_api.transferTo( userId, mixin_asset_lists.CNB_ASSET_ID, money, mxUuid ) txt = "{} 打赏你 {} ".format( mxUuid, money ) MIXIN_WS_API.sendUserText( ws, conversationId, userId, txt ) return elif categoryindata == "PLAIN_TEXT": myPrint("PLAIN_TEXT but unkonw:") if __name__ == "__main__": myPrint("main") mixin_api = MIXIN_API(robot_config) mixin_ws = MIXIN_WS_API( on_message=on_message ) mixin_ws.run()
# import json # body = { # "session_secret": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLHhlK0GZCjE6o6/seNz8x0X7r+1zYtACrgJT60GHr5ol9SUFHrTt8qTPfDphxcVA9S8LN4MIowXfIabhP/5FJX3G3wdR4U+U18cFqEiYB+i7uF9ME9Q8RIk/orzeimID97F/sn0XVk8lCCaKUuL1FOHN3J67ox2RWkvMCrIJlrQIDAQAB", # "full_name": "Tom Bot " # } # print(body) # body_in_json = json.dumps(body) # print(body_in_json) from Crypto.PublicKey import RSA from mixin_api import MIXIN_API # from random_word import RandomWords import mixin_config import json PIN = '832047' mixinApiBotInstance = MIXIN_API(mixin_config) print("will verify Pin", mixin_config.pay_pin) pinInfo = mixinApiBotInstance.verifyPin(mixin_config.pay_pin) print(pinInfo) # pinInfo = mixinApiBotInstance.updatePin(PIN,mixin_config.pay_pin)
strPresent_of_asset_withdrawaddress(eachAddress, withdraw_asset_id)) confirm = input("Type YES to withdraw " + withdraw_amount + withdraw_asset_name + " to " + address_selected + "!!:") if (confirm == "YES"): this_uuid = str(uuid.uuid1()) asset_pin = input("pin:") asset_withdraw_result = mixinApiNewUserInstance.withdrawals( address_id, withdraw_amount, "withdraw2" + address_pubkey, this_uuid, asset_pin) return asset_withdraw_result return None mixinApiBotInstance = MIXIN_API(mixin_config) PromptMsg = "Read first user from local file new_users.csv : loaduser\n" PromptMsg += "Read account asset balance : balance\n" PromptMsg += "Read Bitcoin : btcbalance\n" PromptMsg += "Read USDT : usdtbalance\n" PromptMsg += "Read transaction of my account : searchsnapshots\n" PromptMsg += "Read one snapshots info of account : snapshot\n" PromptMsg += "Pay USDT to ExinCore to buy BTC : buybtc\n" PromptMsg += "Create wallet and update PIN : create\n" PromptMsg += "transafer all asset to my account in Mixin Messenger : allmoney\n" PromptMsg += "List account withdraw address : listaddress\n" PromptMsg += "Add new withdraw address for Bitcoin : addbitcoinaddress\n" PromptMsg += "Add new withdraw address for USDT : addusdtaddress\n" PromptMsg += "Remove withdraw address for Bitcoin : removebtcaddress\n" PromptMsg += "Remove withdraw address for Bitcoin : removeusdtaddress\n"