详解微信第三方小程序代开发
微信申请第三方之后可以获取授权方的很多权限,主要的是生码和待开发,生码的第三方授权之前已经写了一篇文章,最近做了小程序待开发,总结一下写下来供大家参考
注意事项:如果在调试过程中返回了错误码请到小程序代开发api页面查看,
小程序代开发使用的域名是你申请第三方时候填写的域名,
小程序代码模板最多只有50个,可以删除然后重新添加。
准备工作:
申请微信第三方并且权限那边要选上代开发,第三方申请成功之后就是准备小程序了,需要两个小程序,一个作为小程序代码库,一个作为用户测试用,需要在第三方授权。
添加小程序代码库: 在第三方那边将小程序添加为开发小程序,然后该小程序就成为了第三方的开发小程序,之后该小程序提交的代码都会存入第三方草稿箱,你可以选择版本添加为模板,一个第三方最 多只能有50个模板。
代开发流程:
post请求公共方法,与微信服务器交互用
代码如下
protected function curl_post( $curlHttp, $postdata ) {
$ch = curl_init(); //用curl发送数据给api
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_URL, $curlHttp );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
$response = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $response, true );
return $result;
}
get请求公共方法,与微信服务器交互用
代码如下
protected function buildRequestForm( array $param, $method, $target='',$jump=false) {
$sHtml = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><form id='autoSubmit' action='".$target."' method='".$method."'>";
if ( !empty( $param ) ) {
foreach( $param as $key => $value ) {
$sHtml.= "<input type='hidden' name='".$key."' value='".urldecode($value)."'/>";
}
}
$sHtml .= "</form>";
if($jump) $sHtml = $sHtml."<script>document.getElementById(\"autoSubmit\").submit();</script>";
return $sHtml;
}
获取授权方api调用拼成access_token公共方法
代码如下
protectd function getAccessToken( $appId ) {
$accessToken = '';
if ( empty( $appId ) ) {
return $accessToken;
}
// 中间的逻辑自己填充
return $accessToken;
}
首先是开发一套小程序并且上传,之后再第三方里边把该版本设置成模板,这个时候你就用了模板id(用于代码指定用)
通过调用微信接口,给用户小程序指定小程序代码
代码如下
public function commitCode() {
$appId = input( 'app_id', '' );
$descript = input( 'descript', '测试代码指定' );
$version = input( 'version', 'V.1.0' );
$templateId = input( 'template_id', 1 );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
if ( empty( $templateId ) && ( $templateId != 0 ) ) {
$this->error( '模板id不能为空' );
return;
}
$accessToken = $this->getAccessToken( $appId );
// 个人信息我给清除了,空字符部分请自己补充
$extJson = array(
'extAppid' => $appId,
'ext' => array(
'attr1' => 'value1'
),
'extPages' => array(
'pages/index/index' => array(
'navigationBarTitleText' => ''
),
'pages/media/media' => array(
'navigationBarTitleText' => ''
)
),
'pages' => array(
'pages/index/index',
'pages/media/media'
),
'window' => array(
'backgroundColor' => '#f8f8f8',
'navigationBarTextStyle' => 'white',
"navigationBarTitleText" => "",
'navigationBarBackgroundColor' => '#2b3b48'
),
'tabBar' => array(
'list' => array(
array(
'text' => '',
'pagePath' => 'pages/index/index',
),
array(
'text' => '',
'pagePath' => 'pages/media/media',
)
)
),
'networkTimeout' => array(
'request' => 10000,
'uploadFile' => 10000,
'downloadFile' => 10000,
'connectSocket' => 10000
)
);
$params = array(
'template_id' => $templateId,
'user_version' => $version,
'user_desc' => $descript,
'ext_json' => json_encode( $extJson, JSON_UNESCAPED_UNICODE )
);
$result = $this->curl_post( 'https://api.weixin.qq.com/wxa/commit"htmlcode">
public function getExpCode() {
$appId = input( 'app_id', '' );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
$accessToken = $this->getAccessToken( $appId );
if ( empty( $accessToken ) ) {
$this->error( '获取授权accessToken错误' );
return;
}
$params = array(
'access_token' => $accessToken
);
$result = $this->buildRequestForm( $params, 'GET', 'https://api.weixin.qq.com/wxa/get_qrcode"htmlcode">
public function bindTester() {
$appId = input( 'app_id', '' );
$wxNumber = input( 'wx_number', '' );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
if ( empty( $wxNumber ) ) {
$this->error( 微信号不能为空 );
return;
}
$accessToken = $this->getAccessToken( $appId );
if ( empty( $accessToken ) ) {
$this->error( '获取授权accessToken错误' );
return;
}
$params = array(
'wechatid' => $wxNumber
);
$result = $this->curl_post( 'https://api.weixin.qq.com/wxa/bind_tester"htmlcode">
public function getCategory() {
$appId = input( 'app_id', '' );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
$accessToken = $this->getAccessToken( $appId );
if ( empty( $accessToken ) ) {
$this->error( '获取授权accessToken错误' );
return;
}
$params = array(
'access_token' => $accessToken
);
$result = $this->buildRequestForm( $params, 'GET', 'https://api.weixin.qq.com/wxa/get_category"htmlcode">
public function submitAudit() {
$appId = input( 'app_id', '' );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
$accessToken = $this->getAccessToken( $appId );
if ( empty( $accessToken ) ) {
$this->error( '获取授权accessToken错误' );
return;
}
$params = array(
'item_list' => array(
array(
'address' => 'pages/index/index',
'tag' => 'IT科技',
'first_class' => 'IT科技',
'second_class' => '硬件与设备',
'title' => '生成二维码'
),
array(
'address' => 'pages/media/media',
'tag' => '工具',
'first_class' => '工具',
'second_class' => '办公',
'title' => '多媒体上传'
)
)
);
$result = $this->curl_post( 'https://api.weixin.qq.com/wxa/submit_audit"htmlcode">
public function getAuditStatus (){
$appId = input( 'app_id', '' );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
$accessToken = $this->getAccessToken( $appId );
if ( empty( $accessToken ) ) {
$this->error( '获取授权accessToken错误' );
return;
}
$params = array(
'auditid' => 12334
);
$result = $this->curl_post( 'https://api.weixin.qq.com/wxa/get_auditstatus"htmlcode">
public function release (){
$appId = input( 'app_id', '' );
if ( empty( $appId ) ) {
$this->error( appid不能为空 );
return;
}
$accessToken = $this->getAccessToken( $appId );
if ( empty( $accessToken ) ) {
$this->error( '获取授权accessToken错误' );
return;
}
$result = $this->curl_post( 'https://api.weixin.qq.com/wxa/release?access_token='.$accessToken, '{}' );
print_r($result);
exit;
return;
}
就这样,小程序代开发就完成了,逻辑很简单,代码也没难度,本文章的代码仅供大家参考,如果有问题请评论指出,我尽量补充。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无详解微信第三方小程序代开发的评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]