123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\Repositories\Eloquent;
- use App\Repositories\Eloquent\BaseRepository;
- use App\Repositories\Contracts\ThirdWxInterface;
- use GuzzleHttp\Client as httpClient;
- /**
- *
- * @author lilin
- *
- */
- class ThirdWxFacadeRepository extends BaseRepository implements ThirdWxInterface
- {
- public function authorization()
- {
- $url = config('console.thirdWx.url');
- $weid = config('console.thirdWx.weid');
- $key = config('console.thirdWx.key');
- $time = time();
- $token = md5(md5($key.$weid.$time));
- try {
- $params = [
- 'ap' => 'api',
- 'op' => 'core',
- 'task' => 'toAuthorize',
- 'weid' => $weid,
- 'time' => $time,
- 'token' => $token,
- 'back_url' => urlencode(config('console.thirdWx.backUrl'))
- ];
- self::setLog(self::TYPENAME.'请求参数', $this->startTime(), $params);
- $queryArr = [];
- foreach ($params as $key=>$param){
- $queryArr[] = $key.'='.$param;
- }
- $result = $url.'?'.implode('&', $queryArr);
- self::setLog(self::TYPENAME.'返回结果111', $this->startTime(), ['result'=>$result]);
- return $this->response($result);
- } catch (\Exception $e) {
- $this->setLog(self::TYPENAME.'getAccessToken 远程请求失败', $this->startTime, [$e->getMessage()]);
- return $this->error()->fail();
- }
- }
- public function getUserInfo($weichatUid)
- {
- $url = config('console.thirdWx.url') . self::USERINFO_URL;
- $key = config('console.thirdWx.key');
- $time = time();
- $token = md5(md5($key.$weichatUid.$time));
- try {
- $params = [
- 'wechat_uid' => $weichatUid,
- 'time' => $time,
- 'token' => $token,
- ];
- $client = new httpClient();
- $res = $client->request('post', $url, ['form_params'=>$params]);
- $body = $res->getBody();
- $data = json_decode($body);
- // echo json_encode($url);
- // echo "<br />";
- // echo json_encode($params);
- // echo "<br />";
- // echo json_encode($data); exit;
- return $this->response($data);
- } catch (\Exception $e) {
- $this->setLog(self::TYPENAME.'getAccessToken 远程请求失败', $this->startTime, [$e->getMessage()]);
- $this->error()->fail();
- }
- }
- public function getJsSdk(string $weid, string $urls)
- {
- $url = config('console.thirdWx.url') . self::JSSDK_URL.'&weid='.$weid;
- try {
- $params = [
- 'url' => $urls
- ];
- $client = new httpClient();
- $res = $client->request('post', $url, ['form_params'=>$params]);
- $body = $res->getBody();
- self::setLog(self::TYPENAME, $this->startTime(), [$body]);
- $data = json_decode($body);
- return $this->response($data);
- } catch (\Exception $e) {
- $this->setLog(self::TYPENAME.'getJsSdk 远程请求失败', $this->startTime, [$e->getMessage()]);
- $this->error()->fail();
- }
- }
- }
|