Index.php 10 KB

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