GC0202 /
ThinkLibrary
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DtApp\ThinkLibrary\service\decent; |
||
| 4 | |||
| 5 | use DtApp\ThinkLibrary\exception\DtaException; |
||
| 6 | use DtApp\ThinkLibrary\facade\Xmls; |
||
| 7 | use DtApp\ThinkLibrary\Service; |
||
| 8 | use think\exception\HttpException; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * 缴费平台 |
||
| 12 | * Class EJiAoFei |
||
| 13 | * @package DtApp\ThinkLibrary\service\decent |
||
| 14 | */ |
||
| 15 | class EJiAoFei extends Service |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * 待请求的链接 |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $api, $method = ''; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * 由鼎信商务提供 |
||
| 25 | * @var |
||
| 26 | */ |
||
| 27 | private $userid, $pwd, $key = ''; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * 需要发送的的参数 |
||
| 31 | * @var |
||
| 32 | */ |
||
| 33 | private $param; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * 响应内容 |
||
| 37 | * @var |
||
| 38 | */ |
||
| 39 | private $output; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * ip:端口 |
||
| 43 | * @param string $api |
||
| 44 | * @return $this |
||
| 45 | */ |
||
| 46 | public function api(string $api): self |
||
| 47 | { |
||
| 48 | $this->api = $api; |
||
| 49 | return $this; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * 由鼎信商务提供 |
||
| 54 | * @param string $userid |
||
| 55 | * @return $this |
||
| 56 | */ |
||
| 57 | public function userid(string $userid): self |
||
| 58 | { |
||
| 59 | $this->userid = $userid; |
||
| 60 | return $this; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * 由鼎信商务提供 |
||
| 65 | * @param string $pwd |
||
| 66 | * @return $this |
||
| 67 | */ |
||
| 68 | public function pwd(string $pwd): self |
||
| 69 | { |
||
| 70 | $this->pwd = $pwd; |
||
| 71 | return $this; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * 由鼎信商务提供 |
||
| 76 | * @param string $key |
||
| 77 | * @return $this |
||
| 78 | */ |
||
| 79 | public function key(string $key): self |
||
| 80 | { |
||
| 81 | $this->key = $key; |
||
| 82 | return $this; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * 话费充值 |
||
| 87 | * @param string $orderid 用户提交的订单号 用户提交的订单号,最长32位(用户保证其唯一性) |
||
| 88 | * @param int $face 充值面值 以元为单位,包含10、20、30、50、100、200、300、500 移动联通电信 |
||
| 89 | * @param string $account 手机号码 需要充值的手机号码 |
||
| 90 | * @param int $amount 购买数量 只能为1 |
||
| 91 | * @return $this |
||
| 92 | */ |
||
| 93 | public function chongZhi(string $orderid, int $face, string $account, int $amount = 1): self |
||
| 94 | { |
||
| 95 | $this->method = 'chongzhi_jkorders'; |
||
| 96 | $this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&face={$face}&account={$account}&amount={$amount}"; |
||
| 97 | return $this; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * 通用查询 |
||
| 102 | * @param string $orderid 用户提交的订单号 用户提交的订单号,最长32位(用户保证其唯一性) |
||
| 103 | * @return $this |
||
| 104 | */ |
||
| 105 | public function query(string $orderid): self |
||
| 106 | { |
||
| 107 | $this->method = 'query_jkorders'; |
||
| 108 | $this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}"; |
||
| 109 | return $this; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * 用户余额查询 |
||
| 114 | * @return $this |
||
| 115 | */ |
||
| 116 | public function money(): self |
||
| 117 | { |
||
| 118 | $this->method = 'money_jkuser'; |
||
| 119 | $this->param = "userid={$this->userid}&pwd={$this->pwd}"; |
||
| 120 | return $this; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * 腾讯充值 |
||
| 125 | * @param string $orderid 用户提交的订单号 用户提交的订单号,最长32位(用户保证其唯一性) |
||
| 126 | * @param string $account QQ号 需要充值的QQ号 |
||
| 127 | * @param int $productid 产品id 可以通过queryTXproduct查询 |
||
| 128 | * @param int $amount 购买数量 |
||
| 129 | * @param string $ip 充值QQ号ip 可以为空 |
||
| 130 | * @param string $times 时间戳 格式:yyyyMMddhhmmss |
||
| 131 | * @return $this |
||
| 132 | */ |
||
| 133 | public function txchongzhi(string $orderid, string $account, int $productid, int $amount, string $ip, string $times): self |
||
| 134 | { |
||
| 135 | $this->method = 'txchongzhi'; |
||
| 136 | $this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&productid={$productid}&amount={$amount}&ip={$ip}×={$times}"; |
||
| 137 | return $this; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * 可充值腾讯产品查询 |
||
| 142 | * @return $this |
||
| 143 | */ |
||
| 144 | public function queryTXproduct(): self |
||
| 145 | { |
||
| 146 | $this->method = 'queryTXproduct'; |
||
| 147 | $this->param = "userid={$this->userid}&pwd={$this->pwd}"; |
||
| 148 | return $this; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * 流量充值 |
||
| 153 | * @param string $orderid 用户提交的订单号 用户提交的订单号,最长32位(用户保证其唯一性) |
||
| 154 | * @param string $account 充值手机号 需要充值的手机号 |
||
| 155 | * @param int $gprs 充值流量值 单位:MB(具体流量值请咨询商务) |
||
| 156 | * @param int $area 充值流量范围 0 全国流量,1 省内流量 |
||
| 157 | * @param int $effecttime 生效日期 0 即时生效,1次日生效,2 次月生效 |
||
| 158 | * @param int $validity 流量有效期 传入月数,0为当月有效 |
||
| 159 | * @param string $times 时间戳 格式:yyyyMMddhhmmss |
||
| 160 | * @return $this |
||
| 161 | */ |
||
| 162 | public function gprsChongzhiAdvance(string $orderid, string $account, int $gprs, int $area, int $effecttime, int $validity, string $times): self |
||
| 163 | { |
||
| 164 | $this->method = 'gprsChongzhiAdvance'; |
||
| 165 | $this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&gprs={$gprs}&area={$area}&effecttime={$effecttime}&validity={$validity}×={$times}"; |
||
| 166 | return $this; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * 会员订单成本价查询 |
||
| 171 | * @param string $orderid 用户订单号 用户提交订单号 |
||
| 172 | * @return $this |
||
| 173 | */ |
||
| 174 | public function checkCost(string $orderid): self |
||
| 175 | { |
||
| 176 | $this->method = 'checkCost'; |
||
| 177 | $this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}"; |
||
| 178 | return $this; |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @throws DtaException |
||
| 183 | */ |
||
| 184 | public function toArray() |
||
| 185 | { |
||
| 186 | //首先检测是否支持curl |
||
| 187 | if (!extension_loaded("curl")) { |
||
| 188 | throw new HttpException(404, '请开启curl模块!'); |
||
| 189 | } |
||
| 190 | if (empty($this->api)) { |
||
| 191 | throw new DtaException('请检查api参数'); |
||
| 192 | } |
||
| 193 | $this->http(); |
||
| 194 | // 正常 |
||
| 195 | if (is_array($this->output)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 196 | return $this->output; |
||
| 197 | } |
||
| 198 | if (is_object($this->output)) { |
||
|
0 ignored issues
–
show
|
|||
| 199 | $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE); |
||
| 200 | } |
||
| 201 | $this->output = json_decode($this->output, true); |
||
| 202 | return $this->output; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * 网络请求 |
||
| 207 | */ |
||
| 208 | private function http(): void |
||
| 209 | { |
||
| 210 | //生成签名 |
||
| 211 | $sign = $this->createSign(); |
||
| 212 | //组织参数 |
||
| 213 | $this->param .= '&userkey=' . $sign; |
||
| 214 | $url = "http://" . $this->api . "/" . $this->method . ".do?{$this->param}"; |
||
| 215 | $result = file_get_contents($url); |
||
| 216 | $result = Xmls::toArray($result); |
||
| 217 | $this->output = $result; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * 签名 |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | private function createSign(): string |
||
| 225 | { |
||
| 226 | $sign = str_replace(array("&", "="), array("", ""), $this->param); |
||
| 227 | $sign .= $this->key; |
||
| 228 | $sign = strtoupper(md5($sign)); |
||
| 229 | return $sign; |
||
| 230 | } |
||
| 231 | } |