|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+namespace app\controller\api\store\service;
|
|
|
4
|
+
|
|
|
5
|
+use think\App;
|
|
|
6
|
+use crmeb\basic\BaseController;
|
|
|
7
|
+
|
|
|
8
|
+class Huafei extends BaseController
|
|
|
9
|
+{
|
|
|
10
|
+
|
|
|
11
|
+ public $appkey = '1077740514';
|
|
|
12
|
+ public $secretKey = 'f154a106d56d804fcc640d9da4844b0c';
|
|
|
13
|
+ // 生产
|
|
|
14
|
+ public $gatewayUrl = "https://router.wikeyun.cn";
|
|
|
15
|
+ // 备用
|
|
|
16
|
+// public $gatewayUrl = "https://router.wikeyun.cn/rest";
|
|
|
17
|
+
|
|
|
18
|
+ public $format = "json";
|
|
|
19
|
+ /** 是否打开入参check**/
|
|
|
20
|
+ protected $signMethod = "md5";
|
|
|
21
|
+ protected $apiVersion = "1.0";
|
|
|
22
|
+
|
|
|
23
|
+
|
|
|
24
|
+ public function __construct(App $app)
|
|
|
25
|
+ {
|
|
|
26
|
+ parent::__construct($app);
|
|
|
27
|
+ }
|
|
|
28
|
+
|
|
|
29
|
+ //充值话费推送
|
|
|
30
|
+ public function recharge(){
|
|
|
31
|
+ $request['store_id'] = '9189';
|
|
|
32
|
+ $request['mobile'] = '18973958920';
|
|
|
33
|
+ $request['money'] = 100;
|
|
|
34
|
+ $request['recharge_type'] = 1;
|
|
|
35
|
+ $request['notify_url'] = 'https://api.gdjbp.com//api/huafei/notify';
|
|
|
36
|
+ $arr = $this->execute('/rest/Recharge/PushOrder', $request);
|
|
|
37
|
+ return app('json')->success('话费推送成功', $arr);
|
|
|
38
|
+ }
|
|
|
39
|
+
|
|
|
40
|
+ protected function generateSign($params){
|
|
|
41
|
+ ksort($params);
|
|
|
42
|
+ $stringToBeSigned = $this->secretKey;
|
|
|
43
|
+ foreach ($params as $k => $v)
|
|
|
44
|
+ {
|
|
|
45
|
+ if (is_array($v)) {
|
|
|
46
|
+ $stringToBeSigned .= $k;
|
|
|
47
|
+ }else{
|
|
|
48
|
+ if ("@" != substr($v, 0, 1)) {
|
|
|
49
|
+ $stringToBeSigned .= "$k$v";
|
|
|
50
|
+ }
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+ unset($k, $v);
|
|
|
54
|
+ $stringToBeSigned .= $this->secretKey;
|
|
|
55
|
+ return strtoupper(md5($stringToBeSigned));
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+
|
|
|
59
|
+ public function curl($url, $postFields = null,$timeOut = 20){
|
|
|
60
|
+ $ch = curl_init();
|
|
|
61
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
62
|
+ curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
|
|
63
|
+ curl_setopt($ch, CURLOPT_REFERER, 'https://api.gdjbp.com');
|
|
|
64
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
65
|
+ curl_setopt($ch, CURLOPT_TIMEOUT,$timeOut);
|
|
|
66
|
+ //https 请求
|
|
|
67
|
+ if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
|
|
|
68
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
69
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
70
|
+ }
|
|
|
71
|
+ if (is_array($postFields) && 0 < count($postFields)){
|
|
|
72
|
+ $postBodyString = "";
|
|
|
73
|
+ $postMultipart = false;
|
|
|
74
|
+ foreach ($postFields as $k => $v){
|
|
|
75
|
+ if("@" != substr($v, 0, 1))//判断是不是文件上传
|
|
|
76
|
+ {
|
|
|
77
|
+ $postBodyString .= "$k=" . urlencode($v) . "&";
|
|
|
78
|
+ }
|
|
|
79
|
+ else//文件上传用multipart/form-data,否则用www-form-urlencoded
|
|
|
80
|
+ {
|
|
|
81
|
+ $postMultipart = true;
|
|
|
82
|
+ }
|
|
|
83
|
+ $postMultipart = true;
|
|
|
84
|
+ }
|
|
|
85
|
+ unset($k, $v);
|
|
|
86
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
87
|
+ if ($postMultipart){
|
|
|
88
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
|
|
89
|
+ }else{
|
|
|
90
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
|
|
|
91
|
+ }
|
|
|
92
|
+ }
|
|
|
93
|
+ $reponse = curl_exec($ch);
|
|
|
94
|
+ curl_close($ch);
|
|
|
95
|
+ return json_decode($reponse, true);
|
|
|
96
|
+ }
|
|
|
97
|
+
|
|
|
98
|
+ /**
|
|
|
99
|
+ * request api接口后缀,如 /recharge/pushOrder
|
|
|
100
|
+ * apiParams 业务参数 数组
|
|
|
101
|
+ */
|
|
|
102
|
+ public function execute($request, $apiParams ,$timeOut =20){
|
|
|
103
|
+ //组装系统参数
|
|
|
104
|
+ $sysParams["app_key"] = $this->appkey;
|
|
|
105
|
+ $sysParams["v"] = $this->apiVersion;
|
|
|
106
|
+ $sysParams["format"] = $this->format;
|
|
|
107
|
+ $sysParams["timestamp"] = time();
|
|
|
108
|
+ $sysParams["client"] = '';
|
|
|
109
|
+ //签名
|
|
|
110
|
+ $sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams));
|
|
|
111
|
+
|
|
|
112
|
+ //系统参数放入GET请求串
|
|
|
113
|
+ //$requestUrl = $this->gatewayUrl.$sysParams['method']. "?";
|
|
|
114
|
+ $requestUrl = $this->gatewayUrl.$request. "?";
|
|
|
115
|
+
|
|
|
116
|
+ foreach ($sysParams as $sysParamKey => $sysParamValue){
|
|
|
117
|
+ $requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
|
|
|
118
|
+ }
|
|
|
119
|
+ $requestUrl = substr($requestUrl, 0, -1);
|
|
|
120
|
+ return $this->curl($requestUrl, $apiParams ,$timeOut);
|
|
|
121
|
+ }
|
|
|
122
|
+}
|