· 9 years ago · Jul 20, 2016, 03:15 PM
1<?php namespace Sunweb\CS\Components;
2
3use Session;
4use URL;
5use Cms\Classes\ComponentBase;
6
7use waylaidwanderer\SteamCommunity\Enum\LoginResult;
8use waylaidwanderer\SteamCommunity\MobileAuth\WgTokenInvalidException;
9use waylaidwanderer\SteamCommunity\SteamCommunity;
10
11class TestSteam extends ComponentBase
12{
13
14 /*
15var config = {
16 serverPort: 8080,
17 bot: {
18 steamid: '',
19 username: '',
20 password: '',
21 secret: '\/=',
22 identity_secret: '+='
23 },
24 apiKey: '',
25 domain: '',
26 secretKey: '', //
27 admins: [
28 ''
29 ]
30}
31 */
32 protected $config2 = [
33
34 "username"=>'',
35 "password"=>'',
36 "apiKeyDomain"=>'', // "optional, can remove this line",
37 "mobileAuth"=>[
38 "identitySecret"=>"",
39 "sharedSecret"=>"",
40 // "deviceId"=>""
41 ]
42
43 ];
44
45
46 protected $config = [
47
48 "username"=>'',
49 "password"=>'',
50 "apiKeyDomain"=>'', // "optional, can remove this line",
51 //"mobileAuth"=>FALSE
52 ];
53
54 public function componentDetails()
55 {
56 return [
57 'name' => 'test steam',
58 'description' => 'test steam.'
59 ];
60 }
61
62 /**
63 * Executed when this component is bound to a page or layout.
64 */
65 public function onRun()
66 {
67 date_default_timezone_set('America/Los_Angeles');
68
69
70 $this->config2["mobileAuth"]['deviceId']=$this->generateDeviceID();
71
72 $steam = new SteamCommunity($this->config2, dirname(__FILE__));
73 $loginResult = $steam->doLogin();
74 var_Dump($loginResult);
75 $iter=0;
76 while ($loginResult != LoginResult::LoginOkay) {
77 if(++$iter>2){
78 break;
79 }
80 if ($loginResult == LoginResult::Need2FA) {
81 if ($steam->mobileAuth() == null) {
82 $authCode = var_dump('Enter 2FA code: ');
83 break;
84 $steam->setTwoFactorCode($authCode);
85 } else {
86 $authCode = $steam->mobileAuth()->steamGuard()->generateSteamGuardCode();
87
88 $steam->setTwoFactorCode($authCode);
89 var_dump('Generated Steam Guard code: ' . $authCode."\n");
90 }
91 $loginResult = $steam->doLogin();
92 } else if ($loginResult == LoginResult::NeedEmail) {
93 $authCode = var_dump('Enter Steam Guard code from email: ');
94 break;
95 $steam->setEmailCode($authCode);
96 $loginResult = $steam->doLogin();
97 } else if ($loginResult == LoginResult::NeedCaptcha) {
98 $captchaCode = var_dump('Enter captcha (' . $steam->getCaptchaLink() . '): ');
99 break;
100 $steam->setCaptchaText($captchaCode);
101 $loginResult = $steam->doLogin();
102 } else {
103 break;
104 }
105 var_dump("Login result: {$loginResult}.");
106 }
107
108 if ($loginResult == LoginResult::LoginOkay) {
109 var_Dump('Logged in successfully.');
110
111 $tradeOffers = $steam->tradeOffers();
112 var_dump($tradeOffers->getTradeOffersViaAPI(true));
113
114 //$trade = $tradeOffers->createTrade(12345);
115 //$trade->addOtherItem(730, 2, "12345678");
116 //var_dump($trade->send());
117 //var_dump($trade->sendWithToken('token'));
118
119 var_dump(['balance'=>$steam->market()->getWalletBalance()]);
120
121 try {
122 $confirmations = $steam->mobileAuth()->confirmations()->fetchConfirmations();
123 foreach ($confirmations as $confirmation) {
124 var_dump($steam->mobileAuth()->confirmations()->getConfirmationTradeOfferId($confirmation));
125 var_dump($steam->mobileAuth()->confirmations()->acceptConfirmation($confirmation));
126 }
127 } catch (WgTokenInvalidException $ex) {
128 // session invalid
129 $steam->mobileAuth()->refreshMobileSession();
130 }
131 }
132 }
133
134 public function getProviders()
135 {
136
137
138 }
139
140 function GUID()
141 {
142 if (function_exists('com_create_guid') === true)
143 {
144 return trim(com_create_guid(), '{}');
145 }
146
147 return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
148 }
149
150
151 private function generateDeviceID(){
152 // Generation Device_ID
153 $hash = sha1($this->GUID());
154 return 'android:'.$hash;
155 }
156
157}