Skip to content

Commit

Permalink
[更新]完善开放平台小程序支持
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujingli committed May 11, 2018
1 parent 602ef0a commit 6d2f92b
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 0 deletions.
87 changes: 87 additions & 0 deletions WeChat/Mini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------

namespace WeChat;

use WeChat\Contracts\BasicWeChat;

/**
* 小程序管理权限集
* Class Mini
* @package WeChat
*/
class Mini extends BasicWeChat
{
/**
* 1. 获取公众号关联的小程序
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getLinkWxamp()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, [], true);
}

/**
* 2. 关联小程序
* @param string $miniAppid 小程序appid
* @param integer $notifyUsers 是否发送模板消息通知公众号粉丝
* @param integer $showProfile 是否展示公众号主页中
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function linkWxamp($miniAppid, $notifyUsers = 1, $showProfile = 1)
{
$url = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, [
'appid' => $miniAppid,
'notify_users' => $notifyUsers,
'show_profile' => $showProfile,
]);
}

/**
* 3.解除已关联的小程序
* @param string $miniAppid 小程序appid
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function unlinkWxamp($miniAppid)
{
$url = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['appid' => $miniAppid]);
}

/**
* 第三方平台调用快速注册API完成注册
* @param string $ticket 公众号扫码授权的凭证(公众平台扫码页面回跳到第三方平台时携带)
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function fastRegister($ticket)
{
$url = 'https://api.weixin.qq.com/cgi-bin/account/fastregister?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['ticket' => $ticket]);
}

}
198 changes: 198 additions & 0 deletions WeMini/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?php

// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------

namespace WeMini;

use WeChat\Contracts\BasicWeChat;

/**
* 微信小程序账号管理
* Class Account
* @package WeMini
*/
class Account extends BasicWeChat
{
/**
* 2.1 获取帐号基本信息
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAccountBasicinfo()
{
$url = 'https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
}

/**
* 2.2 小程序名称设置及改名
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setNickname(array $data)
{
$url = 'https://api.weixin.qq.com/wxa/setnickname?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
}

/**
* 2.3 小程序改名审核状态查询
* @param integer $audit_id 审核单id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryChangeNicknameAuditStatus($audit_id)
{
$url = "https://api.weixin.qq.com/wxa/api_wxa_querynickname?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['audit_id' => $audit_id]);
}

/**
*
* 2.4 微信认证名称检测
* @param string $nickname 微信认证名称
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function checkWxVerifyNickname($nickname)
{
$url = "https://api.weixin.qq.com/wxa/api_wxa_querynickname?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['nick_name' => $nickname]);
}

/**
* 2.5 修改头像
* @param string $headImgMediaId 头像素材media_id
* @param integer $x1 裁剪框左上角x坐标(取值范围:[0, 1])
* @param integer $y1 裁剪框左上角y坐标(取值范围:[0, 1])
* @param integer $x2 裁剪框右下角x坐标(取值范围:[0, 1])
* @param integer $y2 裁剪框右下角y坐标(取值范围:[0, 1])
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function modifyHeadImage($headImgMediaId, $x1 = 0, $y1 = 0, $x2 = 1, $y2 = 1)
{
$url = "https://api.weixin.qq.com/cgi-bin/account/modifyheadimage?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['head_img_media_id' => $headImgMediaId]);
}

/**
* 2.6 修改功能介绍
* @param string $signature 功能介绍(简介)
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException]
*/
public function modifySignature($signature)
{
$url = "https://api.weixin.qq.com/cgi-bin/account/modifysignature?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['signature' => $signature]);
}

/**
* 2.7.3跳转至第三方平台,第三方平台调用快速注册API完成管理员换绑。
* @param string $taskid 换绑管理员任务序列号(公众平台最终点击提交回跳到第三方平台时携带)
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function componentreBindAdmin($taskid)
{
$url = 'https://api.weixin.qq.com/cgi- bin/account/componentrebindadmin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['taskid' => $taskid]);
}

/**
* 3.1 获取账号可以设置的所有类目
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAllCategories()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/getallcategories?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
}

/**
* 3.2 添加类目
* @param array $categories
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addCategory($categories)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/addcategory?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['categories' => $categories]);
}

/**
* 3.3 删除类目
* @param string $first 一级类目ID
* @param string $second 二级类目ID
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delCategroy($first, $second)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['first' => $first, 'second' => $second]);
}

/**
* 3.4 获取账号已经设置的所有类目
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getCategory()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/getcategory?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
}

/**
* 3.5 修改类目
* @param string $first 一级类目ID
* @param string $second 二级类目ID
* @param array $certicates
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function modifyCategory($first, $second, $certicates)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['first' => $first, 'second' => $second, 'categories' => $categories]);
}
}
29 changes: 29 additions & 0 deletions WeOpen/MiniApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,33 @@ public function session($appid, $code)
return json_decode(Tools::get($url), true);
}

/**
* 1.注册流程及接口说明
* @param string $authorizerAppid 公众号的appid
* @param integer $copyWxVerify 是否复用公众号的资质进行微信认证(1:申请复用资质进行微信 认证 0:不申请)
* @param string $redirectUri 用户扫码授权后,MP 扫码页面将跳转到该地址(注:1.链接需 urlencode 2.Host 需和第三方平台在微信开放平台上面填写的登 录授权的发起页域名一致)
* @return string
*/
public function getCopyRegisterMiniUrl($authorizerAppid, $copyWxVerify, $redirectUri)
{
$redirectUri = urlencode($redirectUri);
$componentAppid = $this->config->get('component_appid');
return "https://mp.weixin.qq.com/cgi-bin/fastregisterauth?appid={$authorizerAppid}&component_appid={$componentAppid}&copy_wx_verify={$copyWxVerify}&redirect_uri={$redirectUri}";
}


/**
* 2.7.1 从第三方平台跳转至微信公众平台授权注册页面
* @param string $authorizerAppid 公众号的 appid
* @param string $redirectUri 新管理员信息填写完成点击提交后,将跳转到该地址
* @return string
*/
public function getComponentreBindAdmin($authorizerAppid, $redirectUri)
{
$redirectUri = urlencode($redirectUri);
$componentAppid = $this->config->get('component_appid');
return "https://mp.weixin.qq.com/wxopen/componentrebindadmin?appid={$authorizerAppid}&component_appid={$componentAppid}&redirect_uri={$redirectUri}";
}


}
21 changes: 21 additions & 0 deletions WeOpen/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ public function getOauthAccessToken($authorizer_appid)
return $result !== false ? $result : false;
}

/**
* 取当前所有已授权的帐号基本信息
* @param integer $count 拉取数量,最大为500
* @param integer $offset 偏移位置/起始位置
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAuthorizerList($count = 500, $offset = 0)
{
$component_appid = $this->config->get('component_appid');
$component_access_token = $this->getComponentAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list?component_access_token={$component_access_token}";
$result = $this->httpPostForJson($url, [
'count' => $count,
'offset' => $offset,
'component_appid' => $component_appid,
]);
return $result !== false ? $result : false;
}

/**
* 创建指定授权公众号接口实例
* @param string $name 需要加载的接口实例名称
Expand Down

0 comments on commit 6d2f92b

Please sign in to comment.