Index.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use think\facade\Db;
  5. class Index extends BaseController
  6. {
  7. function test(){
  8. ini_set("display_errors","On");
  9. error_reporting(E_ALL );
  10. //actionBegin();
  11. }
  12. function pay(){
  13. return view();
  14. }
  15. protected $baseUrl = 'http://localhost';
  16. protected $client;
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. $this->url_user = "http://pm.yz314.com/index.php/";
  21. $this->url_www = "http://pm.yz314.com/index.php/";
  22. //$this->client = new \GuzzleHttp\Client( [ 'base_uri' => 'http://www.s.cn', 'http_errors' => false, ]);
  23. $this->cookieJar = new \GuzzleHttp\Cookie\CookieJar();
  24. $options = [
  25. 'base_uri' => $this->url_user,
  26. 'timeout' => 10.0,
  27. 'cookies' => $this->cookieJar,
  28. 'cookies' => true,
  29. //'proxy' => 'http://192.168.16.16:8888',
  30. // 'allow_redirects' => false,
  31. ];
  32. $options['proxy'] = 'http://192.168.16.96:8888';
  33. $this->client = new \GuzzleHttp\Client($options);
  34. }
  35. /**
  36. * @param $url
  37. * @param $method
  38. * @param $param
  39. * @param string $type
  40. * 'json' => ['foo' => 'bar']
  41. * 'multipart' => [ [ 'name' => 'field_name', 'contents' => 'abc' ]]
  42. * @return mixed
  43. */
  44. function request($url, $method, $param, $header = [])
  45. {
  46. $method = strtolower($method);
  47. //if(empty($type)){
  48. //$type = ($method == 'post') ? 'form_params' : 'query';
  49. //}
  50. if (empty($header)) {
  51. // $header = [
  52. // 'User-Agent' => 'testing/1.0',
  53. // 'X-Wtfs-Signature' => 'testtesttesttesttest-test-test-test-testtesttesttest',
  54. // 'Referer' => 'http://pm.yz314.com//front/view/app/user/bindPhone.html',
  55. // ];
  56. }
  57. if ($method == 'post') {
  58. $r = $this->client->request('POST', $url, [
  59. "form_params" => $param,
  60. 'cookies' => $this->cookieJar,
  61. 'headers' => $header,
  62. ]);
  63. } else {
  64. $r = $this->client->request('GET', $url, [
  65. 'query' => $param,
  66. 'cookies' => $this->cookieJar,
  67. 'headers' => $header,
  68. ]);
  69. }
  70. return $r;
  71. }
  72. public function index()
  73. {
  74. return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V6<br/><span style="font-size:30px">13载初心不改 - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
  75. }
  76. public function hello($name = 'ThinkPHP6')
  77. {
  78. return 'hello,' . $name;
  79. }
  80. protected $users = [
  81. [
  82. 'keyID' => '123456',
  83. 'keySecret' => '',
  84. ]
  85. ];
  86. /**
  87. * $templateId
  88. * $param
  89. * $phone_number
  90. * countryID
  91. */
  92. function sms_send()
  93. {
  94. //Db::name('user');
  95. $param = I('paramValues');
  96. $dbUserInfo = [];
  97. $dbUserInfo['keyID']= "123456";
  98. $dbUserInfo['keySecret']= "12345678";
  99. $headerAuth = [];
  100. $postNonce= I('nonce');
  101. $postTime= I('time');
  102. $postKey_id = $headerAuth['key_id'];
  103. $postSign = $headerAuth['sign'];
  104. $sign = $this->makeSign($postNonce,$postTime,$dbUserInfo['key_secret']);
  105. if($sign != $postSign){
  106. $ret=[];
  107. $ret['code']=0;
  108. $ret['msg']='authentication failure';
  109. echo json_encode($ret);
  110. exit;
  111. }
  112. $templateId = I('template_id');
  113. $templateId = "sms_123456";
  114. $phoneNumber = I('phoneNumber'); //8615812345678
  115. $templateContent = '短信内容 {$content} [test]';
  116. $smsContent = str_replace('{$user}',$param['user'],$templateContent);
  117. $countryID = I('countryID');
  118. $countryID = 'CN';
  119. $url = "https://www.huaweiita.com:17131/apiaccess/sms/sendTemplateSms/v1";
  120. $params = [];
  121. $params['smsTemplateId'] = '695db7b5-6d4f-4791-aea0-f733f2ef06ce';
  122. $params['paramValues'] = $param; // paramValues:{"user":"XXX"}
  123. $params['msisdn'] = $phoneNumber;
  124. $params['countryID'] = $countryID;
  125. $ret = curl_huawei_sms($url, json_encode($params));
  126. //$sign = "";
  127. }
  128. function makeSign($nonce,$time,$key){
  129. $signRawString = $nonce . $time . $key;
  130. return base64_encode(hash('sha256',$signRawString));
  131. }
  132. /**
  133. *
  134. * 检测签名
  135. */
  136. public function CheckSign()
  137. {
  138. $sign = $this->MakeSign();
  139. if($this->GetSign() == $sign){
  140. return true;
  141. }
  142. throw new WxPayException("签名错误!");
  143. }
  144. function send()
  145. {
  146. $url = "https://www.huaweiita.com:17131/apiaccess/sms/sendTemplateSms/v1";
  147. $params = [];
  148. $params['smsTemplateId'] = '695db7b5-6d4f-4791-aea0-f733f2ef06ce';
  149. $paramValues = [];
  150. $paramValues['user'] = 'test1';
  151. $params['paramValues'] = $paramValues; // paramValues:{"user":"XXX"}
  152. $params['msisdn'] = '8615821868265';
  153. $params['countryID'] = 'CN';
  154. $ret = curl_huawei_sms($url, json_encode($params));
  155. }
  156. function province()
  157. {
  158. $r = Db::name('province')->select();
  159. $all = [];
  160. $all['name'] = 'all';
  161. $allProvince = [];
  162. foreach ($r as $k => $v) {
  163. $mCity = Db::name('city');
  164. $where = [];
  165. $where['provinceCode'] = $v['code'];
  166. $rCity = $mCity->where($where)->select()->toArray();
  167. // echo $mCity->getLastSql();
  168. //$cityNames = array_column($rCity,'name');
  169. $cityNames = [];
  170. //var_dump($rCity);
  171. $cityOfCurrentProvince = [];
  172. foreach ($rCity as $kCity => $vCity) {
  173. $mArea = Db::name('area');
  174. $area = [];
  175. $where2 = [];
  176. $where2['provinceCode'] = $vCity['provinceCode'];
  177. $where2['cityCode'] = $vCity['code'];
  178. $rArea = $mArea->where($where2)->select()->toArray();
  179. $areaNames = array_column($rArea, 'name');
  180. $city = [];
  181. $city['name'] = $vCity['name'];
  182. $city['children'] = $areaNames;
  183. $cityOfCurrentProvince[] = $city;
  184. }
  185. $province = [];
  186. $province['name'] = $v['name'];
  187. $province['children'] = $cityOfCurrentProvince;
  188. $allProvince[] = $province;
  189. }
  190. $all['children'] = $allProvince;
  191. file_put_contents('./data.json', json_encode($all, JSON_UNESCAPED_UNICODE));
  192. dump($allProvince);
  193. exit;
  194. }
  195. function payment()
  196. {
  197. $url = "https://www.apifabric.com.cn/apiaccess/payment/paymentGateway/checkout/v1/payment";
  198. $params = [
  199. 'originalAmount' => '6',
  200. 'currency' => 'USD',
  201. 'intent' => 'sale',
  202. 'shortCode' => '100000703',
  203. 'commodityDesc' => 'PGW payment',
  204. 'note2Payer' => 'Good Choice',
  205. 'merchantInvoiceNumber' => 'abc',
  206. 'discountedAmount' => '1',
  207. ];
  208. $params['originalAmount'] = I('totalPrice');
  209. $params = json_encode($params);
  210. $params = '{"originalAmount":"6","currency":"USD","intent":"sale","shortCode":"100000703","commodityDesc":"PGW payment","note2Payer":"Good Choice","merchantInvoiceNumber":"abc","discountedAmount":"1"}';
  211. //$params = var_export(json_decode($params,true),true);
  212. $headers[] = 'X-APP-Key: APP ID';
  213. $headers[] = 'Authorization:Bearer Access-Token';
  214. $headers[] = 'Content-Type: application/json; charset=UTF-8';
  215. $ret = curl_post_json_pay($url, $params, $headers);
  216. //echo $ret;exit;
  217. $ret = json_decode($ret,true);
  218. $ret['isSuccess'] = true;
  219. return jsonp($ret);
  220. }
  221. function execute()
  222. {
  223. $paymentID = I('paymentID');
  224. //$paymentID = 'PP27F16000000000051006';
  225. $url = "https://www.apifabric.com.cn/apiaccess/payment/paymentGateway/checkout/v1/{$paymentID}/execute";
  226. //$params = [];
  227. //$params['couponID'] = '1';
  228. //$params = json_encode($params);
  229. $params='';
  230. $headers[] = 'X-APP-Key: APP ID';
  231. $headers[] = 'Authorization:Bearer Access-Token';
  232. $headers[] = 'Content-Type: application/json; charset=UTF-8';
  233. $ret = curl_post_json_pay($url, $params, $headers);
  234. $ret = json_decode($ret,true);
  235. $ret['isSuccess'] = true;
  236. return jsonp($ret);
  237. }
  238. function recharge()
  239. {
  240. $url = "http://test.jifenfu.net:59085/orderCard2!order.do";
  241. $params = [];
  242. $params['signMsg'] = '';
  243. $params['submitTimestamp'] = '';
  244. $params['pid'] = '';
  245. $params['cardBatchNo'] = '';
  246. $params['password'] = '';
  247. $params['orderId'] = '';
  248. $params['customerNo'] = '';
  249. $params['orderQuantity'] = '';
  250. $params['orderTime'] = '';
  251. $params['orderPoints'] = '';
  252. $sign =
  253. $response = $this->request($url, 'post', $params);
  254. //$ret = curl_post_json($url, json_encode($params));
  255. }
  256. }