forked from leadermt/any-balance-providers
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Первая версия провайдера.
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<provider> | ||
<id version="1">ab-bonus-magnit</id> | ||
<api flags="no_browser"/> | ||
<name>Магнит</name> | ||
<description html="true"><![CDATA[ | ||
<p>Предоставляет информацию о балансе на бонусной карте сети магазинов Магнит https://magnit.ru</p> | ||
<p>Информация берется из личного кабинета https://moy.magnit.ru</p> | ||
]]></description> | ||
<instruction html="true"><![CDATA[ | ||
<p>Для использования провайдера необходимо активировать карту Магнит в личном кабинете https://moy.magnit.ru </p> | ||
]]></instruction> | ||
<author>AnyBalance Team <info@anybalance.ru></author> | ||
<depends> | ||
<module id="library"/> | ||
</depends> | ||
<files> | ||
<icon>icon.png</icon> | ||
<preferences>preferences.xml</preferences> | ||
<js>main.js</js> | ||
<history>history.xml</history> | ||
</files> | ||
<counters> | ||
<counter id="balance" name="Баланс" units=" Б"/> | ||
<counter id="fio" name="ФИО" type="text"/> | ||
<counter id="status" name="Статус" type="text"/> | ||
</counters> | ||
<keywords></keywords> | ||
<type>bonus</type> | ||
<country>ru</country> | ||
</provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<history> | ||
<change version="1" date="2020-02-24"> | ||
- Первая версия провайдера. | ||
</change> | ||
<!-- | ||
<change version="2" date="2014-02-01"> | ||
- | ||
</change> | ||
--> | ||
</history> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
| ||
/** | ||
Провайдер AnyBalance (http://any-balance-providers.googlecode.com) | ||
*/ | ||
|
||
var g_headers = { | ||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | ||
'Accept-Charset': 'windows-1251,utf-8;q=0.7,*;q=0.3', | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
// Mobile | ||
//'User-Agent':'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.187 Mobile Safari/534.11+', | ||
// Desktop | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36', | ||
}; | ||
|
||
var g_apiHeaders = { | ||
'Connection': 'Keep-Alive', | ||
'User-Agent': 'okhttp/3.12.0' | ||
}; | ||
|
||
function callApi(verb, postParams, addH){ | ||
var method = 'GET'; | ||
var h = g_apiHeaders; | ||
if(isset(postParams)){ | ||
method = 'POST'; | ||
} | ||
|
||
if(addH) | ||
h = addHeaders(addH, h); | ||
|
||
var html = AnyBalance.requestPost('https://moy.magnit.ru/b2c/' + verb, postParams, h, {HTTP_METHOD: method}); | ||
|
||
if(!html) | ||
return {__empty: true}; | ||
|
||
var json = getJson(html); | ||
if(json.error && json.error !== 'OTP_REQUIRED'){ | ||
AnyBalance.trace(html); | ||
throw new AnyBalance.Error(json.message, null, /парол|password/i.test(json.error.description)); | ||
} | ||
|
||
return json; | ||
} | ||
|
||
function login(){ | ||
var prefs = AnyBalance.getPreferences(); | ||
delete g_apiHeaders.Authorization; | ||
|
||
var json = callApi('login', { | ||
username: '7' + prefs.login, | ||
password: prefs.password, | ||
channel: 'O', | ||
mobileSystem: 'A' | ||
}); | ||
|
||
if(json.error === 'OTP_REQUIRED'){ | ||
AnyBalance.trace(json.message); | ||
var code = AnyBalance.retrieveCode('Пожалуйста, введите код из SMS для входа в ЛК Магнит', null, {inputType: 'number', timeout: 180000}); | ||
json = callApi('login', { | ||
username: '7' + prefs.login, | ||
password: prefs.password, | ||
channel: 'O', | ||
mobileSystem: 'A' | ||
}, { | ||
'X-CLM-OTP-Token': code | ||
}); | ||
} | ||
|
||
if(!json.access_token){ | ||
AnyBalance.trace(JSON.stringify(json)); | ||
throw AnyBalance.Error('Не удалось зайти в личный кабинет. Сайт изменен?'); | ||
} | ||
|
||
AnyBalance.setData('login', prefs.login); | ||
AnyBalance.setData('access_token', json.access_token); | ||
AnyBalance.setData('refresh_token', json.refresh_token); | ||
AnyBalance.saveData(); | ||
} | ||
|
||
function setAuthHeaders(){ | ||
var at = AnyBalance.getData('access_token'); | ||
g_apiHeaders.Authorization = 'Bearer ' + at; | ||
//g_apiHeaders.queryMode = '2'; | ||
} | ||
|
||
function main() { | ||
var prefs = AnyBalance.getPreferences(); | ||
AnyBalance.setDefaultCharset('utf-8'); | ||
|
||
AB.checkEmpty(prefs.login, 'Введите номер телефона!'); | ||
AB.checkEmpty(/^\d{10}$/.test(prefs.login), 'Введите 10 цифр номера телефона без пробелов и разделителей, например, 9261234567 !'); | ||
AB.checkEmpty(prefs.password, 'Введите пароль!'); | ||
|
||
var _login = AnyBalance.getData('login'); | ||
if(_login !== prefs.login){ | ||
login(); | ||
} | ||
|
||
setAuthHeaders(); | ||
var json; | ||
|
||
try{ | ||
json = callApi('me'); | ||
if(json.anonymized) | ||
throw new AnyBalance.Error('Not logged in'); | ||
}catch(e){ | ||
//Надо бы по рефреш токену восстановить здесь доступ | ||
//но пока просто логин | ||
login(); | ||
setAuthHeaders(); | ||
|
||
json = callApi('me'); | ||
if(json.anonymized){ | ||
AnyBalance.trace(JSON.stringify(json)); | ||
throw new AnyBalance.Error('Не удалось зайти в личный кабинет после попытки авторизации. Сайт изменен?'); | ||
} | ||
} | ||
|
||
|
||
var result = { | ||
success: true | ||
}; | ||
|
||
AB.getParam(json.mainPointsBalance/100, result, 'balance'); | ||
AB.getParam(json.firstName, result, 'fio'); | ||
AB.getParam(json.mainIdentifier, result, '__tariff'); | ||
AB.getParam(json.statusName, result, 'status'); | ||
|
||
AnyBalance.setResult(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen> | ||
<EditTextPreference | ||
title="Номер телефона" | ||
key="login" | ||
summary="||{@s}" | ||
obligatory="true" | ||
inputType="number" | ||
dialogTitle="Номер телефона" | ||
positiveButtonText="ОК" | ||
negativeButtonText="Отмена" | ||
dialogMessage="Введите 10 цифр номера телефона без пробелов и разделителей. Например, 9261234567"> | ||
</EditTextPreference> | ||
<EditTextPreference | ||
title="Пароль" | ||
key="password" | ||
summary="||***********" | ||
obligatory="true" | ||
dialogTitle="Пароль" | ||
positiveButtonText="ОК" | ||
negativeButtonText="Отмена" | ||
dialogMessage="Введите пароль, используемый для входа в личный кабинет" | ||
inputType="textPassword"> | ||
</EditTextPreference> | ||
</PreferenceScreen> |