网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序第三方代開發

發布時間:2018-04-21 08:56 所屬欄目:小程序開發教程

微信申請第三方之后可以獲取授權方的很多權限,主要的是生碼和待開發,生碼的第三方授權之前已經寫了一篇文章,最近做了小程序待開發,總結一下寫下來供大家參考

注意事項:如果在調試過程中返回了錯誤碼請到小程序代開發api頁面查看,

     小程序代開發使用的域名是你申請第三方時候填寫的域名,

     小程序代碼模板最多只有50個,可以刪除然后重新添加。

準備工作:

  申請微信第三方并且權限那邊要選上代開發,第三方申請成功之后就是準備小程序了,需要兩個小程序,一個作為小程序代碼庫,一個作為用戶測試用,需要在第三方授權。

  添加小程序代碼庫: 在第三方那邊將小程序添加為開發小程序,然后該小程序就成為了第三方的開發小程序,之后該小程序提交的代碼都會存入第三方草稿箱,你可以選擇版本添加為模板,一個第三方最 多只能有50個模板。

代開發流程:

  post請求公共方法,與微信服務器交互用

  代碼如下

 1    protected function curl_post( $curlHttp, $postdata ) {
 2         $ch = curl_init(); //用curl發送數據給api
 3         curl_setopt( $ch, CURLOPT_POST, true );
 4         curl_setopt( $ch, CURLOPT_POST, true );
 5         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
 6         curl_setopt( $ch, CURLOPT_URL, $curlHttp );
 7         curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
 8         curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
 9         curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
10 
11         $response = curl_exec( $ch );
12         curl_close( $ch );
13         $result = json_decode( $response, true );
14         return $result;
15     }

  get請求公共方法,與微信服務器交互用 代碼如下

 1 protected function buildRequestForm( array $param, $method, $target='',$jump=false) {
 2         $sHtml = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><form id='autoSubmit' action='".$target."' method='".$method."'>";
 3 
 4         if ( !empty( $param ) ) {
 5             foreach( $param as $key => $value ) {
 6                 $sHtml.= "<input type='hidden' name='".$key."' value='".urldecode($value)."'/>";
 7             }
 8         }
 9         $sHtml .= "</form>";
10 
11         if($jump) $sHtml = $sHtml."<script>document.getElementById(\"autoSubmit\").submit();</script>";
12 
13         return $sHtml;
14     }

  獲取授權方api調用拼成access_token公共方法 代碼如下:

 1 protectd function getAccessToken( $appId ) {
 2         $accessToken = '';
 3 
 4         if ( empty( $appId ) ) {
 5             return $accessToken;
 6         }
 7         
 8         // 中間的邏輯自己填充
 9 
10         return $accessToken;
11     }

  首先是開發一套小程序并且上傳,之后再第三方里邊把該版本設置成模板,這個時候你就用了模板id(用于代碼指定用)

  通過調用微信接口,給用戶小程序指定小程序代碼

  代碼如下

 1 public function commitCode() {
 2         $appId = input( 'app_id', '' );
 3         $descript = input( 'descript', '測試代碼指定' );
 4         $version = input( 'version', 'V.1.0' );
 5         $templateId = input( 'template_id', 1 );
 6         if ( empty( $appId ) ) {
 7             $this->error( appid不能為空 );
 8             return;
 9         }
10 
11         if ( empty( $templateId ) && ( $templateId != 0 ) ) {
12             $this->error( '模板id不能為空' );
13             return;
14         }
15 
16         $accessToken = $this->getAccessToken( $appId );
17 
18         // 個人信息我給清除了,空字符部分請自己補充
19         $extJson = array(
20             'extAppid' => $appId,
21             'ext' => array(
22                 'attr1' => 'value1'
23             ),
24             'extPages' => array(
25                     'pages/index/index' => array(
26                         'navigationBarTitleText'    => ''
27                     ),
28                     'pages/media/media' => array(
29                         'navigationBarTitleText'    => ''
30                     )
31             ),
32             'pages' => array(
33                     'pages/index/index',
34                     'pages/media/media'
35             ),
36             'window' => array(
37                     'backgroundColor'           => '#f8f8f8',
38                     'navigationBarTextStyle'    => 'white',
39                     "navigationBarTitleText"    => "",
40                     'navigationBarBackgroundColor' => '#2b3b48'
41             ),
42             'tabBar' => array(
43                 'list' => array(
44                     array(
45                         'text'      => '',
46                         'pagePath'  => 'pages/index/index',
47                     ),
48                     array(
49                         'text'      => '',
50                         'pagePath'  => 'pages/media/media',
51                     )
52                 )
53             ),
54             'networkTimeout' => array(
55                     'request'       =>  10000,
56                     'uploadFile'    =>  10000,
57                     'downloadFile'  =>  10000,
58                     'connectSocket' =>  10000
59             )
60         );
61 
62         $params = array(
63             'template_id'   => $templateId,
64             'user_version'  => $version,
65             'user_desc'     => $descript,
66             'ext_json'      => json_encode( $extJson, JSON_UNESCAPED_UNICODE )
67         );
68         $result = $this->curl_post( 'https://api.weixin.qq.com/wxa/commit?access_token='.$accessToken, json_encode( $params, JSON_UNESCAPED_UNICODE ) );
69         if ( empty( $result ) || !empty( $result['errcode'] ) ) {
70             $this->error( '代碼指定錯誤' );
71             return;
72         }
73 
74         $this->success( '操作成功' );
75         return;
76     }

  指定代碼之后就是查看功能是否正常了,所以就要調用微信接口獲取體驗二維碼掃碼體驗,

  代碼如下

 1 public function getExpCode() {
 2         $appId = input( 'app_id', '' );
 3         if ( empty( $appId ) ) {
 4             $this->error( appid不能為空 );
 5             return;
 6         }
 7 
 8         $accessToken = $this->getAccessToken( $appId );
 9         if ( empty( $accessToken ) ) {
10             $this->error( '獲取授權accessToken錯誤' );
11             return;
12         }
13 
14         $params = array(
15             'access_token' => $accessToken
16         );


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23818.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×