国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

ホームページ WeChat アプレット WeChatの開発 最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

Jul 25, 2018 pm 02:16 PM
php 微信 WeChat アプレット

本文章是自己編寫的,用微信第三方平臺開發(fā)實現(xiàn)小程序業(yè)務,代碼很全,每一步都有詳細介紹,供大家學習參考。

第一步:申請微信開放平臺帳號并創(chuàng)建第三方平臺

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

第二步:公眾號/小程序授權給第三方平臺

<?php
/*
*    微信第三方平臺授權流程
*/
namespace app\home\controller;
class Weixin extends Common
{
    private $appid = &#39;wx3e******165c&#39;;            //第三方平臺應用appid
    private $appsecret = &#39;13e**********d039&#39;;     //第三方平臺應用appsecret
    private $token = &#39;ePF58******Q2Ae&#39;;           //第三方平臺應用token(消息校驗Token)
    private $encodingAesKey = &#39;bzH***FCamD&#39;;      //第三方平臺應用Key(消息加解密Key)
    private $component_ticket= &#39;ticket@**xv-g&#39;;   //微信后臺推送的ticket,用于獲取第三方平臺接口調(diào)用憑據(jù)
    
    /*
    * 掃碼授權,注意此URL必須放置在頁面當中用戶點擊進行跳轉(zhuǎn),不能通過程序跳轉(zhuǎn),否則將出現(xiàn)“請確認授權入口頁所在域名,與授權后回調(diào)頁所在域名相同....”錯誤
    * @params string $redirect_uri : 掃碼成功后的回調(diào)地址
    * @params int $auth_type : 授權類型,1公眾號,2小程序,3公眾號/小程序同時展現(xiàn)。不傳參數(shù)默認都展示    
    */
    public function startAuth($redirect_uri,$auth_type = 3)
    {
        $url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=".$this->appid."&pre_auth_code=".$this->get_pre_auth_code()."&redirect_uri=".urlencode($redirect_uri)."&auth_type=".$auth_type;
        return $url;
    }
    
    /*
    * 獲取第三方平臺access_token
    * 注意,此值應保存,代碼這里沒保存
    */
    private function get_component_access_token()
    {
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
        $data = &#39;{
            "component_appid":"&#39;.$this->appid.&#39;" ,
            "component_appsecret": "&#39;.$this->appsecret.&#39;",
            "component_verify_ticket": "&#39;.$this->component_ticket.&#39;"
        }&#39;;
        $ret = json_decode($this->https_post($url,$data));
        if($ret->errcode == 0) {
            return $ret->component_access_token;
        } else {
            return $ret->errcode;
        }
    }
    /*
    *  第三方平臺方獲取預授權碼pre_auth_code
    */
    private function get_pre_auth_code()
    {
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=".$this->get_component_access_token();
        $data = &#39;{"component_appid":"&#39;.$this->appid.&#39;"}&#39;;
        $ret = json_decode($this->https_post($url,$data));
        if($ret->errcode == 0) {
            return $ret->pre_auth_code;
        } else {
            return $ret->errcode;
        }
    }
    
    /*
    * 發(fā)起POST網(wǎng)絡提交
    * @params string $url : 網(wǎng)絡地址
    * @params json $data : 發(fā)送的json格式數(shù)據(jù)
    */
    private function https_post($url,$data)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
     /*
    * 發(fā)起GET網(wǎng)絡提交
    * @params string $url : 網(wǎng)絡地址
    */
    private function https_get($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); 
        curl_setopt($curl, CURLOPT_HEADER, FALSE) ; 
        curl_setopt($curl, CURLOPT_TIMEOUT,60);
        if (curl_errno($curl)) {
            return &#39;Errno&#39;.curl_error($curl);
        }
        else{$result=curl_exec($curl);}
        curl_close($curl);
        return $result;
    }
}
<?php
/*
*    接收微信官方推送的ticket值以及取消授權等操作
*/
namespace app\home\controller;
use think\Db;
class Openoauth extends Common
{
    private $appid = &#39;wx3e******165c&#39;;            //第三方平臺應用appid
    private $appsecret = &#39;13e**********d039&#39;;     //第三方平臺應用appsecret
    private $token = &#39;ePF58******Q2Ae&#39;;           //第三方平臺應用token(消息校驗Token)
    private $encodingAesKey = &#39;bzH***FCamD&#39;;      //第三方平臺應用Key(消息加解密Key)
    private $component_ticket= &#39;ticket@**xv-g&#39;;   //微信后臺推送的ticket,用于獲取第三方平臺接口調(diào)用憑據(jù)
    /*
    *    接收微信官方推送的消息(每10分鐘1次)
    *    這里需要引入微信官方提供的加解密碼示例包
    *    官方文檔:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318479&token=&lang=zh_CN
    *    示例包下載:https://wximg.gtimg.com/shake_tv/mpwiki/cryptoDemo.zip
    */
    public function index()
    {
        $encryptMsg = file_get_contents("php://input");
        $xml_tree = new \DOMDocument();
        $xml_tree->loadXML($encryptMsg);
        $xml_array = $xml_tree->getElementsByTagName("Encrypt");
        $encrypt = $xml_array->item(0)->nodeValue;
        require_once(&#39;wxBizMsgCrypt.php&#39;);
        $Prpcrypt = new \Prpcrypt($this->encodingAesKey);
        $postData = $Prpcrypt->decrypt($encrypt, $this->appid);
        if ($postData[0] != 0) {
            return $postData[0];
        } else {
            $msg = $postData[1];
            $xml = new \DOMDocument();
            $xml->loadXML($msg);
            $array_a = $xml->getElementsByTagName("InfoType");
            $infoType = $array_a->item(0)->nodeValue;
            if ($infoType == "unauthorized") {
                //取消公眾號/小程序授權
                $array_b = $xml->getElementsByTagName("AuthorizerAppid");
                $AuthorizerAppid = $array_b->item(0)->nodeValue;    //公眾號/小程序appid
                $where = array("type" => 1, "appid" => $AuthorizerAppid);
                $save = array("authorizer_access_token" => "", "authorizer_refresh_token" => "", "authorizer_expires" => 0);
                Db::name("wxuser")->where($where)->update($save);   //公眾號取消授權
                Db::name("wxminiprograms")->where(&#39;authorizer_appid&#39;,$AuthorizerAppid)->update($save);   //小程序取消授權
            } else if ($infoType == "component_verify_ticket") {
                //微信官方推送的ticket值
                $array_e = $xml->getElementsByTagName("ComponentVerifyTicket");
                $component_verify_ticket = $array_e->item(0)->nodeValue;
                if (Db::name("weixin_account")->where(array("type" => 1))->update(array("component_verify_ticket" => $component_verify_ticket, "date_time" => time()))) {
                    $this->updateAccessToken($component_verify_ticket);
                    echo "success";
                }
            }
        }
    }
    
    /*
     * 更新component_access_token
     * @params string $component_verify_ticket
     * */
    private function updateAccessToken($component_verify_ticket)
    {
        $weixin_account = Db::name(&#39;weixin_account&#39;)->where([&#39;type&#39;=>1])->field(&#39;id,appId,appSecret,component_access_token,token_expires&#39;)->find();
        if($weixin_account[&#39;token_expires&#39;] <= time() ) {
            $apiUrl = &#39;https://api.weixin.qq.com/cgi-bin/component/api_component_token&#39;;
            $data = &#39;{"component_appid":"&#39;.$weixin_account[&#39;appId&#39;].&#39;" ,"component_appsecret": "&#39;.$weixin_account[&#39;appSecret&#39;].&#39;","component_verify_ticket": "&#39;.$component_verify_ticket.&#39;"}&#39;;
            $json = json_decode(_request($apiUrl,$data));
            if(isset($json->component_access_token)) {
                Db::name(&#39;weixin_account&#39;)->where([&#39;id&#39;=>$weixin_account[&#39;id&#39;]])->update([&#39;component_access_token&#39;=>$json->component_access_token,&#39;token_expires&#39;=>time()+7200]);
            }
        }
    }
}
<?php
/*
*    代小程序?qū)崿F(xiàn)業(yè)務
*/
namespace app\home\model;
use think\Model;
use think\Db;
use think\Cache;
class Miniprogram extends Model
{
    private $thirdAppId;        //開放平臺appid
    private $encodingAesKey;    //開放平臺encodingAesKey
    private $thirdToken;        //開放平臺token
    private $thirdAccessToken;  //開放平臺access_token

    private $authorizer_appid;
    private  $authorizer_access_token;
    private  $authorizer_refresh_token;

    public function __construct($appid)
    {
        $weixin_account = Db::name(&#39;weixin_account&#39;)->where([&#39;type&#39; => 1])->field(&#39;token,encodingAesKey,appId,component_access_token&#39;)->find();
        if ($weixin_account) {
            $this->thirdAppId = $weixin_account[&#39;appId&#39;];
            $this->encodingAesKey = $weixin_account[&#39;encodingAesKey&#39;];
            $this->thirdToken = $weixin_account[&#39;token&#39;];
            $this->thirdAccessToken = $weixin_account[&#39;component_access_token&#39;];

            $miniprogram = Db::name(&#39;wxminiprograms&#39;)->where(&#39;authorizer_appid&#39;,$appid)
                ->field(&#39;authorizer_access_token,authorizer_refresh_token,authorizer_expires&#39;)->find();
            if($miniprogram){
                $this->authorizer_appid = $appid;
                if(time() > $miniprogram[&#39;authorizer_expires&#39;]){
                    $miniapp = $this->update_authorizer_access_token($appid,$miniprogram[&#39;authorizer_refresh_token&#39;]);
                    if($miniapp) {
                        $this->authorizer_access_token = $miniapp->authorizer_access_token;
                        $this->authorizer_refresh_token = $miniapp->authorizer_refresh_token;
                    } else {
                        $this->errorLog("更新小程序access_token失敗,appid:".$this->authorizer_appid,&#39;&#39;);
                        exit;
                    }
                } else {
                    $this->authorizer_access_token = $miniprogram[&#39;authorizer_access_token&#39;];
                    $this->authorizer_refresh_token = $miniprogram[&#39;authorizer_refresh_token&#39;];
                }

            } else {
                $this->errorLog("小程序不存在,appid:".$this->authorizer_appid,&#39;&#39;);
                exit;
            }
        } else {
            $this->errorLog("請增加微信第三方公眾號平臺賬戶信息",&#39;&#39;);
            exit;
        }
    }

    /*
     * 設置小程序服務器地址,無需加https前綴,但域名必須可以通過https訪問
     * @params string / array $domains : 域名地址。只接收一維數(shù)組。
     * */
    public  function setServerDomain($domain = &#39;test.moh.cc&#39;)
    {
        $url = "https://api.weixin.qq.com/wxa/modify_domain?access_token=".$this->authorizer_access_token;
        if(is_array($domain)) {
            $https = &#39;&#39;; $wss = &#39;&#39;;
            foreach ($domain as $key => $value) {
                $https .= &#39;"https://&#39;.$value.&#39;",&#39;;
                $wss .= &#39;"wss://&#39;.$value.&#39;",&#39;;
            }
            $https = rtrim($https,&#39;,&#39;);
            $wss = rtrim($wss,&#39;,&#39;);
            $data = &#39;{
                "action":"add",
                "requestdomain":[&#39;.$https.&#39;],
                "wsrequestdomain":[&#39;.$wss.&#39;],
                "uploaddomain":[&#39;.$https.&#39;],
                "downloaddomain":[&#39;.$https.&#39;]
            }&#39;;
        } else {
            $data = &#39;{
                "action":"add",
                "requestdomain":"https://&#39;.$domain.&#39;",
                "wsrequestdomain":"wss://&#39;.$domain.&#39;",
                "uploaddomain":"https://&#39;.$domain.&#39;",
                "downloaddomain":"https://&#39;.$domain.&#39;"
            }&#39;;
        }
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("設置小程序服務器地址失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 設置小程序業(yè)務域名,無需加https前綴,但域名必須可以通過https訪問
     * @params string / array $domains : 域名地址。只接收一維數(shù)組。
     * */
    public function setBusinessDomain($domain = &#39;test.moh.cc&#39;)
    {
        $url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=".$this->authorizer_access_token;
        if(is_array($domain)) {
            $https = &#39;&#39;;
            foreach ($domain as $key => $value) {
                $https .= &#39;"https://&#39;.$value.&#39;",&#39;;
            }
            $https = rtrim($https,&#39;,&#39;);
            $data = &#39;{
                "action":"add",
                "webviewdomain":[&#39;.$https.&#39;]
            }&#39;;
        } else {
            $data = &#39;{
                "action":"add",
                "webviewdomain":"https://&#39;.$domain.&#39;"
            }&#39;;
        }

        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("設置小程序業(yè)務域名失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 成員管理,綁定小程序體驗者
     * @params string $wechatid : 體驗者的微信號
     * */
    public function bindMember($wechatid)
    {
        $url = "https://api.weixin.qq.com/wxa/bind_tester?access_token=".$this->authorizer_access_token;
        $data = &#39;{"wechatid":"&#39;.$wechatid.&#39;"}&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("綁定小程序體驗者操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 成員管理,解綁定小程序體驗者
     * @params string $wechatid : 體驗者的微信號
     * */
    public function unBindMember($wechatid)
    {
        $url = "https://api.weixin.qq.com/wxa/unbind_tester?access_token=".$this->authorizer_access_token;
        $data = &#39;{"wechatid":"&#39;.$wechatid.&#39;"}&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("解綁定小程序體驗者操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
    * 成員管理,獲取小程序體驗者列表
    * */
    public function listMember()
    {
        $url = "https://api.weixin.qq.com/wxa/memberauth?access_token=".$this->authorizer_access_token;
        $data = &#39;{"action":"get_experiencer"}&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return $ret->members;
        } else {
            $this->errorLog("獲取小程序體驗者列表操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 為授權的小程序帳號上傳小程序代碼
     * @params int $template_id : 模板ID
     * @params json $ext_json : 小程序配置文件,json格式
     * @params string $user_version : 代碼版本號
     * @params string $user_desc : 代碼描述
     * */
    public function uploadCode($template_id = 1, $user_version = &#39;v1.0.0&#39;, $user_desc = "魔盒CMS小程序模板庫")
    {
        $ext_json = json_encode(&#39;{"extEnable": true,"extAppid": "wx572****bfb","ext":{"appid": "&#39;.$this->authorizer_appid.&#39;"}}&#39;);
        $url = "https://api.weixin.qq.com/wxa/commit?access_token=".$this->authorizer_access_token;
        $data = &#39;{"template_id":"&#39;.$template_id.&#39;","ext_json":&#39;.$ext_json.&#39;,"user_version":"&#39;.$user_version.&#39;","user_desc":"&#39;.$user_desc.&#39;"}&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("為授權的小程序帳號上傳小程序代碼操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 獲取體驗小程序的體驗二維碼
     * @params string $path :   指定體驗版二維碼跳轉(zhuǎn)到某個具體頁面
     * */
    public function getExpVersion($path = &#39;&#39;)
    {
        if($path){
            $url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token=".$this->authorizer_access_token."&path=".urlencode($path);
        } else {
            $url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token=".$this->authorizer_access_token;
        }
        $ret = json_decode(https_get($url));
        if($ret->errcode) {
            $this->errorLog("獲取體驗小程序的體驗二維碼操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        } else {
            return $url;
        }
    }
    /*
     * 提交審核
     * @params string $tag : 小程序標簽,多個標簽以空格分開
     * @params strint $title : 小程序頁面標題,長度不超過32
     * */
    public function submitReview($tag = "魔盒CMS 微信投票 微網(wǎng)站 微信商城" ,$title = "魔盒CMS微信公眾號營銷小程序開發(fā)")
    {
        $first_class = &#39;&#39;;$second_class = &#39;&#39;;$first_id = 0;$second_id = 0;
        $address = "pages/index/index";
        $category = $this->getCategory();
        if(!empty($category)) {
            $first_class = $category[0]->first_class ? $category[0]->first_class : &#39;&#39; ;
            $second_class = $category[0]->second_class ? $category[0]->second_class : &#39;&#39;;
            $first_id = $category[0]->first_id ? $category[0]->first_id : 0;
            $second_id = $category[0]->second_id ? $category[0]->second_id : 0;
        }
        $getpage = $this->getPage();
        if(!empty($getpage) && isset($getpage[0])) {
            $address = $getpage[0];
        }
        $url = "https://api.weixin.qq.com/wxa/submit_audit?access_token=".$this->authorizer_access_token;
        $data = &#39;{
                "item_list":[{
                    "address":"&#39;.$address.&#39;",
                    "tag":"&#39;.$tag.&#39;",
                    "title":"&#39;.$title.&#39;",
                    "first_class":"&#39;.$first_class.&#39;",
                    "second_class":"&#39;.$second_class.&#39;",
                    "first_id":"&#39;.$first_id.&#39;",
                    "second_id":"&#39;.$second_id.&#39;"
                }]
            }&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            Db::name(&#39;wxminiprogram_audit&#39;)->insert([
                &#39;appid&#39;=>$this->authorizer_appid,
                &#39;auditid&#39;=>$ret->auditid,
                &#39;create_time&#39;=>date(&#39;Y-m-d H:i:s&#39;)
            ]);
            return true;
        } else {
            $this->errorLog("小程序提交審核操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 小程序?qū)徍顺坊?     * 單個帳號每天審核撤回次數(shù)最多不超過1次,一個月不超過10次。
     * */
    public function unDoCodeAudit()
    {
        $url = "https://api.weixin.qq.com/wxa/undocodeaudit?access_token=".$this->authorizer_access_token;
        $ret = json_decode(https_get($url));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("小程序?qū)徍顺坊夭僮魇?,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 查詢指定版本的審核狀態(tài)
     * @params string $auditid : 提交審核時獲得的審核id
     * */
    public function getAuditStatus($auditid)
    {
        $url = "https://api.weixin.qq.com/wxa/get_auditstatus?access_token=".$this->authorizer_access_token;
        $data = &#39;{"auditid":"&#39;.$auditid.&#39;"}&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            $reason = $ret->reason ? $ret->reason : &#39;&#39;;
            Db::name(&#39;wxminiprogram_audit&#39;)->where([&#39;appid&#39;=>$this->authorizer_appid,&#39;auditid&#39;=>$auditid])->update([
                &#39;status&#39;=>$ret->status,
                &#39;reason&#39;=>$reason
            ]);
            return true;
        } else {
            $this->errorLog("查詢指定版本的審核狀態(tài)操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 查詢最新一次提交的審核狀態(tài)
     * */
    public function getLastAudit()
    {
        $url = "https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=".$this->authorizer_access_token;
        $ret = json_decode(https_get($url));
        if($ret->errcode == 0) {
            $reason = $ret->reason ? $ret->reason : &#39;&#39;;
            Db::name(&#39;wxminiprogram_audit&#39;)->where([&#39;appid&#39;=>$this->authorizer_appid,&#39;auditid&#39;=>$ret->auditid])->update([
                &#39;status&#39;=>$ret->status,
                &#39;reason&#39;=>$reason
            ]);
            return $ret->auditid;
        } else {
            $this->errorLog("查詢最新一次提交的審核狀態(tài)操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 發(fā)布已通過審核的小程序
     * */
    public function release()
    {
        $url = "https://api.weixin.qq.com/wxa/release?access_token=".$this->authorizer_access_token;
        $data = &#39;{}&#39;;
        $ret = json_decode(https_post($url,$data));
        if($ret->errcode == 0) {
            return true;
        } else {
            $this->errorLog("發(fā)布已通過審核的小程序操作失敗,appid:".$this->authorizer_appid,$ret);
            return $ret->errcode;
        }
    }
    /*
     * 獲取授權小程序帳號的可選類目
     * */
    private function getCategory()
    {
        $url = "https://api.weixin.qq.com/wxa/get_category?access_token=".$this->authorizer_access_token;
        $ret = json_decode(https_get($url));
        if($ret->errcode == 0) {
            return $ret->category_list;
        } else {
            $this->errorLog("獲取授權小程序帳號的可選類目操作失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
     * 獲取小程序的第三方提交代碼的頁面配置
     * */
    private function getPage()
    {
        $url = "https://api.weixin.qq.com/wxa/get_page?access_token=".$this->authorizer_access_token;
        $ret = json_decode(https_get($url));
        if($ret->errcode == 0) {
            return $ret->page_list;
        } else {
            $this->errorLog("獲取小程序的第三方提交代碼的頁面配置失敗,appid:".$this->authorizer_appid,$ret);
            return false;
        }
    }
    /*
    * 更新授權小程序的authorizer_access_token
    * @params string $appid : 小程序appid
    * @params string $refresh_token : 小程序authorizer_refresh_token
    * */
    private function update_authorizer_access_token($appid,$refresh_token)
    {
        $url = &#39;https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=&#39; . $this->thirdAccessToken;
        $data = &#39;{"component_appid":"&#39; . $this->thirdAppId . &#39;","authorizer_appid":"&#39; . $appid . &#39;","authorizer_refresh_token":"&#39; . $refresh_token . &#39;"}&#39;;
        $ret = json_decode(https_post($url, $data));
        if (isset($ret->authorizer_access_token)) {
            Db::name(&#39;wxminiprograms&#39;)->where([&#39;authorizer_appid&#39; => $appid])->update([&#39;authorizer_access_token&#39; => $ret->authorizer_access_token, &#39;authorizer_expires&#39; => (time() + 7200), &#39;authorizer_refresh_token&#39; => $ret->authorizer_refresh_token]);
            return $ret;
        } else {
            $this->errorLog("更新授權小程序的authorizer_access_token操作失敗,appid:".$appid,$ret);
            return null;
        }
    }

    private function errorLog($msg,$ret)
    {
        file_put_contents(ROOT_PATH . &#39;runtime/error/miniprogram.log&#39;, "[" . date(&#39;Y-m-d H:i:s&#39;) . "] ".$msg."," .json_encode($ret).PHP_EOL, FILE_APPEND);
    }
}
<?php
//代小程序?qū)崿F(xiàn)業(yè)務示例包
namespace app\user\controller;
use app\home\model\Miniprogram;
use think\Db;
class Wxminiprogram extends Pub
{
    public $appid = &#39;wx57****1bfb&#39;;    //需要實現(xiàn)業(yè)務小程序appid
    public function index()
    {
        return view();
    }
    public function doAction()
    {
        if(request()->isPost()) {
            $action = input(&#39;action&#39;);
            $mini = new Miniprogram($this->appid);
            if($action == &#39;auth&#39;) {
                //小程序授權
                echo &#39;<script>alert("已授權");history.back();</script>&#39;;
            } elseif($action == &#39;setServerDomain&#39;) {
                //設置小程序服務器域名地址
                if($mini->setServerDomain()){
                    echo &#39;<script>alert("設置小程序服務器域名操作成功");history.back();</script>&#39;;
                } else {
                    echo &#39;<script>alert("設置小程序服務器域名操作失敗或已設置,請查看日志");history.back();</script>&#39;;
                }
            }  elseif($action == &#39;setBusinessDomain&#39;) {
                //設置業(yè)務域名
                if($mini->setBusinessDomain()){
                    echo &#39;<script>alert("設置小程序業(yè)務域名操作成功");history.back();</script>&#39;;
                } else {
                    echo &#39;<script>alert("設置小程序業(yè)務域名操作失敗或已設置,請查看日志");history.back();</script>&#39;;
                }
            }  elseif($action == &#39;bind&#39;) {
                //綁定小程序體驗者
                $wechatid = input(&#39;wechatid&#39;);
                if($wechatid) {
                    if($mini->bindMember($wechatid)){
                        echo &#39;<script>alert("綁定小程序體驗者操作成功");history.back();</script>&#39;;
                    } else {
                        echo &#39;<script>alert("綁定小程序體驗者操作失敗,請查看日志");history.back();</script>&#39;;
                    }
                } else {
                    echo &#39;<script>alert("請輸入微信號");history.back();</script>&#39;;
                }

            }  elseif($action == &#39;uploadCode&#39;) {
                //上傳小程序代碼
                if($mini->uploadCode(2)){
                    echo &#39;<script>alert("上傳小程序代碼操作成功");history.back();</script>&#39;;
                } else {
                    echo &#39;<script>alert("上傳小程序代碼操作失敗,請查看日志");history.back();</script>&#39;;
                }
            }  elseif($action == &#39;getExpVersion&#39;) {
                //獲取體驗小程序的體驗二維碼
                $qrcode = $mini->getExpVersion();
                if($qrcode){
                    echo &#39;<script>window.location.href="&#39;.$qrcode.&#39;";</script>&#39;;
                } else {
                    echo &#39;<script>alert("獲取體驗小程序的體驗二維碼操作失敗");history.back();</script>&#39;;
                }
            } elseif($action == &#39;review&#39;) {
                //提交審核
                $auditid = Db::name(&#39;wxminiprogram_audit&#39;)->where([&#39;appid&#39;=>$this->appid,&#39;status&#39;=>[&#39;neq&#39;,0]])->order(&#39;create_time&#39;,&#39;desc&#39;)->value(&#39;auditid&#39;);
                if($auditid){
                    echo &#39;<script>alert("有待處理的版本,請先處理該版本相關事項再提交新的審核。審核ID:&#39;.$auditid.&#39;");history.back();</script>&#39;;
                } else {
                    if($mini->submitReview()){
                        echo &#39;<script>alert("小程序提交審核操作成功");history.back();</script>&#39;;
                    } else {
                        echo &#39;<script>alert("小程序提交審核操作失敗,請查看日志");history.back();</script>&#39;;
                    }
                }
            } elseif($action == &#39;getAudit&#39;) {
                //查詢指定版本的審核狀態(tài)
                $auditid = input(&#39;auditid&#39;);
                if($auditid) {
                    if($mini->getAuditStatus($auditid)){
                        $audit = Db::name(&#39;wxminiprogram_audit&#39;)->where([&#39;appid&#39;=>$this->appid,&#39;auditid&#39;=>$auditid])->field(&#39;status,reason&#39;)->find();
                        if($audit[&#39;status&#39;] == 0) {
                            echo &#39;<script>alert("該版本審核已通過");history.back();</script>&#39;;
                        } elseif($audit[&#39;status&#39;] == 1) {
                            echo &#39;<script>alert("該版本審核失敗,原因:&#39;.$audit[&#39;reason&#39;].&#39;");history.back();</script>&#39;;
                        } elseif($audit[&#39;status&#39;] == 2) {
                            echo &#39;<script>alert("該版本小程序正在審核中......");history.back();</script>&#39;;
                        } else {
                            echo &#39;<script>alert("未知狀態(tài)......");history.back();</script>&#39;;
                        }
                    } else {
                        echo &#39;<script>alert("查詢指定版本的審核狀態(tài)操作失敗,請查看日志");history.back();</script>&#39;;
                    }
                } else {
                    echo &#39;<script>alert("請輸入要查詢的審核ID");history.back();</script>&#39;;
                }
            } elseif($action == &#39;lastAudit&#39;) {
                //查詢最新一次提交的審核狀態(tài)
                $auditid = $mini->getLastAudit();
                if($auditid){
                    $audit = Db::name(&#39;wxminiprogram_audit&#39;)->where([&#39;appid&#39;=>$this->appid,&#39;auditid&#39;=>$auditid])->field(&#39;status,reason&#39;)->find();
                    if($audit[&#39;status&#39;] == 0) {
                        echo &#39;<script>alert("審核已通過");history.back();</script>&#39;;
                    } elseif($audit[&#39;status&#39;] == 1) {
                        echo &#39;<script>alert("審核失敗,原因:&#39;.$audit[&#39;reason&#39;].&#39;");history.back();</script>&#39;;
                    } elseif($audit[&#39;status&#39;] == 2) {
                        echo &#39;<script>alert("小程序正在審核中......");history.back();</script>&#39;;
                    } else {
                        echo &#39;<script>alert("未知狀態(tài)......");history.back();</script>&#39;;
                    }
                }else {
                    echo &#39;<script>alert("查詢最新一次提交的審核狀態(tài)操作失敗,請查看日志");history.back();</script>&#39;;
                }
            } elseif($action == &#39;release&#39;) {
                //發(fā)布已通過審核的小程序
                $auditid = Db::name(&#39;wxminiprogram_audit&#39;)->where([&#39;appid&#39;=>$this->appid,&#39;status&#39;=>[&#39;neq&#39;,0]])->order(&#39;create_time&#39;,&#39;desc&#39;)->value(&#39;auditid&#39;);
                if($auditid){
                    echo &#39;<script>alert("有待處理的版本,請先處理該版本相關事項再發(fā)布版本。審核ID:&#39;.$auditid.&#39;");history.back();</script>&#39;;
                } else {
                    $errcode = $mini->release();
                    if($errcode){
                        echo &#39;<script>alert("已發(fā)版");history.back();</script>&#39;;
                    } else {
                        echo &#39;<script>alert("發(fā)版失敗,錯誤代碼:&#39;.$errcode.&#39;");history.back();</script>&#39;;
                    }
                }
            }
        }
    }
}

wxminiprograms數(shù)據(jù)表,保存已授權小程序的基本信息及授權相關信息(authorizer_access_token/authorizer_refresh_token)這兩個值很重要,代小程序?qū)崿F(xiàn)業(yè)務基本上是通過這兩個值來實現(xiàn)

-- Adminer 4.6.2 MySQL dump

SET NAMES utf8;
SET time_zone = &#39;+00:00&#39;;
SET foreign_key_checks = 0;
SET sql_mode = &#39;NO_AUTO_VALUE_ON_ZERO&#39;;

DROP TABLE IF EXISTS `wxminiprograms`;
CREATE TABLE `wxminiprograms` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT &#39;ID&#39;,
  `uid` int(10) unsigned NOT NULL COMMENT &#39;用戶ID&#39;,
  `nick_name` varchar(45) DEFAULT NULL COMMENT &#39;微信小程序名稱&#39;,
  `alias` varchar(45) DEFAULT NULL COMMENT &#39;別名&#39;,
  `token` varchar(45) DEFAULT NULL COMMENT &#39;平臺生成的token值&#39;,
  `head_img` varchar(255) DEFAULT NULL COMMENT &#39;微信小程序頭像&#39;,
  `verify_type_info` tinyint(1) DEFAULT NULL COMMENT &#39;授權方認證類型,-1代表未認證,0代表微信認證&#39;,
  `is_show` tinyint(1) DEFAULT &#39;0&#39; COMMENT &#39;是否顯示,0顯示,1隱藏&#39;,
  `user_name` varchar(45) DEFAULT NULL COMMENT &#39;原始ID&#39;,
  `qrcode_url` varchar(255) DEFAULT NULL COMMENT &#39;二維碼圖片的URL&#39;,
  `business_info` varchar(255) DEFAULT NULL COMMENT &#39;json格式。用以了解以下功能的開通狀況(0代表未開通,1代表已開通): open_store:是否開通微信門店功能 open_scan:是否開通微信掃商品功能 open_pay:是否開通微信支付功能 open_card:是否開通微信卡券功能 open_shake:是否開通微信搖一搖功能&#39;,
  `idc` int(10) unsigned DEFAULT NULL COMMENT &#39;idc&#39;,
  `principal_name` varchar(45) DEFAULT NULL COMMENT &#39;小程序的主體名稱&#39;,
  `signature` varchar(255) DEFAULT NULL COMMENT &#39;帳號介紹&#39;,
  `miniprograminfo` varchar(255) DEFAULT NULL COMMENT &#39;json格式。判斷是否為小程序類型授權,包含network小程序已設置的各個服務器域名&#39;,
  `func_info` longtext COMMENT &#39;json格式。權限集列表,ID為17到19時分別代表: 17.帳號管理權限 18.開發(fā)管理權限 19.客服消息管理權限 請注意: 1)該字段的返回不會考慮小程序是否具備該權限集的權限(因為可能部分具備)。&#39;,
  `authorizer_appid` varchar(45) DEFAULT NULL COMMENT &#39;小程序appid&#39;,
  `authorizer_access_token` varchar(255) DEFAULT NULL COMMENT &#39;授權方接口調(diào)用憑據(jù)(在授權的公眾號或小程序具備API權限時,才有此返回值),也簡稱為令牌&#39;,
  `authorizer_expires` int(10) unsigned DEFAULT NULL COMMENT &#39;refresh有效期&#39;,
  `authorizer_refresh_token` varchar(255) DEFAULT NULL COMMENT &#39;接口調(diào)用憑據(jù)刷新令牌&#39;,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT &#39;授權時間&#39;,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=&#39;微信小程序授權列表&#39;;


-- 2018-07-25 09:32:49

wxminiprogram_audit數(shù)據(jù)表,保存提交審核的小程序

-- Adminer 4.6.2 MySQL dump

SET NAMES utf8;
SET time_zone = &#39;+00:00&#39;;
SET foreign_key_checks = 0;
SET sql_mode = &#39;NO_AUTO_VALUE_ON_ZERO&#39;;

DROP TABLE IF EXISTS `wxminiprogram_audit`;
CREATE TABLE `wxminiprogram_audit` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT &#39;ID&#39;,
  `appid` varchar(45) NOT NULL COMMENT &#39;小程序appid&#39;,
  `auditid` varchar(45) NOT NULL COMMENT &#39;審核編號&#39;,
  `status` tinyint(1) unsigned NOT NULL DEFAULT &#39;3&#39; COMMENT &#39;審核狀態(tài),其中0為審核成功,1為審核失敗,2為審核中,3已提交審核&#39;,
  `reason` varchar(255) DEFAULT NULL COMMENT &#39;當status=1,審核被拒絕時,返回的拒絕原因&#39;,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT &#39;提交審核時間&#39;,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=&#39;微信小程序提交審核的小程序&#39;;


-- 2018-07-25 09:35:07

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。

最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。x

相關推薦:

微信開發(fā)公眾號平臺視頻教程

微信公眾平臺開發(fā)者文檔

PHP微信公眾平臺開發(fā)視頻教程

以上が最終的には、WeChatサードパーティプラットフォームを使用してミニプログラムビジネスを承認することで解決しました。の詳細內(nèi)容です。詳細については、PHP 中國語 Web サイトの他の関連記事を參照してください。

このウェブサイトの聲明
この記事の內(nèi)容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當する法的責任を負いません。盜作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undress AI Tool

Undress AI Tool

脫衣畫像を無料で

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

寫真から衣服を削除するオンライン AI ツール。

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中國語版

SublimeText3 中國語版

中國語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

ランプスタックを超えて:現(xiàn)代のエンタープライズアーキテクチャにおけるPHPの役割 ランプスタックを超えて:現(xiàn)代のエンタープライズアーキテクチャにおけるPHPの役割 Jul 27, 2025 am 04:31 AM

phpisStillRelevantinModernenterpriseenvironments.1.modernphp(7.xand8.x)は、パフォーマンスゲイン、stricttyping、jit compilation、andmodernsyntaxを提供し、scaleApplications.2.phpintegrateSeffeCtiveTiveliveTiveliveTiveliveTiveTiveTiveliveTiveStures、

PHPとrabbitmqを使用した回復力のあるマイクロサービスを構築します PHPとrabbitmqを使用した回復力のあるマイクロサービスを構築します Jul 27, 2025 am 04:32 AM

柔軟なPHPマイクロサービスを構築するには、RabbitMQを使用して非同期通信を?qū)g現(xiàn)する必要があります。 2。信頼性を確保するために、永続的なキュー、永続的なメッセージ、リリース確認、手動ACKを構成します。 3.指數(shù)バックオフ再試行、TTL、およびデッドレターキューセキュリティ処理の障害を使用します。 4.監(jiān)督などのツールを使用して、消費者プロセスを保護し、ハートビートメカニズムを有効にしてサービスの健康を確保します。そして最終的に、システムが障害で継続的に動作する能力を?qū)g現(xiàn)します。

PHPでのオブジェクトリレーショナルマッピング(ORM)パフォーマンスチューニング PHPでのオブジェクトリレーショナルマッピング(ORM)パフォーマンスチューニング Jul 29, 2025 am 05:00 AM

n 1クエリの問題を避け、関連するデータを事前にロードすることにより、データベースクエリの數(shù)を減らします。 2.必要なフィールドのみを選択して、メモリと帯域幅を保存するために完全なエンティティをロードしないようにします。 3. DoctrineのセカンダリキャッシュやRedis Cacheの高周波クエリ結(jié)果など、キャッシュ戦略を合理的に使用します。 4.エンティティのライフサイクルを最適化し、クリア()を定期的に呼び出してメモリを解放してメモリオーバーフローを防ぎます。 5.データベースインデックスが存在し、生成されたSQLステートメントを分析して、非効率的なクエリを避けます。 6.変更が不要なシナリオで自動変更追跡を無効にし、パフォーマンスを改善するためにアレイまたは軽量モードを使用します。 ORMを正しく使用するには、SQLモニタリング、キャッシュ、バッチ処理、適切な最適化を組み合わせて、開発効率を維持しながらアプリケーションのパフォーマンスを確保する必要があります。

PHP用の生産対応Docker環(huán)境の作成 PHP用の生産対応Docker環(huán)境の作成 Jul 27, 2025 am 04:32 AM

正しいPHP Basicイメージを使用し、安全で最適化されたDocker環(huán)境を構成することが、生産を?qū)g現(xiàn)するための鍵です。 1.攻撃面を減らしてパフォーマンスを向上させるための基本畫像としてPHP:8.3-fpm-alpineを選択します。 2.カスタムPHP.iniを介して危険な機能を無効にし、エラーディスプレイをオフにし、OpCacheとJITを有効にしてセキュリティとパフォーマンスを強化します。 3. NGINXを逆プロキシとして使用して、機密ファイルへのアクセスを制限し、PHPリクエストをPHP-FPMに正しく転送します。 4.マルチステージ最適化畫像を使用して開発依存関係を削除し、非ルートユーザーを設定してコンテナを?qū)g行します。 5. CRONなどの複數(shù)のプロセスを管理するためのオプションの監(jiān)督。 6.展開前に機密情報漏れがないことを確認します

vscode settings.jsonの場所 vscode settings.jsonの場所 Aug 01, 2025 am 06:12 AM

settings.jsonファイルは、ユーザーレベルまたはワークスペースレベルのパスにあり、VSCODE設定のカスタマイズに使用されます。 1。ユーザーレベルのパス:WindowsはC:\ users \\ appdata \ roaming \ code \ user \ settings.json、macos is/users //settings.json、linux is /home/.config/code/user/settings.json; 2。Workspace-Level Path:.vscode/settings Project Root Directoryの設定

PHPの內(nèi)部ガベージコレクションメカニズムに深く潛ります PHPの內(nèi)部ガベージコレクションメカニズムに深く潛ります Jul 28, 2025 am 04:44 AM

PHPのゴミ収集メカニズムは參照カウントに基づいていますが、周期的な円形のゴミコレクターによって円形の參照を処理する必要があります。 1。変數(shù)への參照がない場合、參照カウントはすぐにメモリを解放します。 2.參照參照により、メモリを自動的にリリースできなくなり、GCを検出およびクリーニングすることがGCに依存します。 3。GCは、「可能なルート」ZVALがしきい値に到達するか、GC_COLLECT_CYCLES()を手動で呼び出すとトリガーされます。 4.長期実行PHPアプリケーションは、メモリの漏れを避けるために、gc_status()を監(jiān)視し、gc_collect_cycles()を呼び出す必要があります。 5.ベストプラクティスには、gc_disable()を使用してパフォーマンスキー領域を最適化し、ormのclear()メソッドを介して繰り返しのオブジェクトを最適化する回路參照の回避が含まれます。

サーバーレス革命:BREFを使用してスケーラブルなPHPアプリケーションを展開します サーバーレス革命:BREFを使用してスケーラブルなPHPアプリケーションを展開します Jul 28, 2025 am 04:39 AM

BREFにより、PHP開発者は、サーバーを管理せずにスケーラブルで費用対効果の高いアプリケーションを構築できます。 1.Brefは、最適化されたPHPランタイムレイヤーを提供し、PHP8.3およびその他のバージョンをサポートし、LaravelやSymfonyなどのフレームワークとシームレスに統(tǒng)合することにより、PHPをAwslambdaにもたらします。 2。展開手順には、次のものが含まれます。Composerを使用してBREFのインストール、httpエンドポイントや職人コマンドなどの関數(shù)とイベントを定義するためにserverless.ymlの構成。 3. serverlessdeployコマンドを?qū)g行して、展開を完了し、Apigatewayを自動的に構成し、アクセスURLを生成します。 4。Lambdaの制限については、Brefは解決策を提供します。

Readonlyプロパティを備えたPHPに不変のオブジェクトを構築します Readonlyプロパティを備えたPHPに不変のオブジェクトを構築します Jul 30, 2025 am 05:40 AM

readonlypropertiesinphp8.2canonlybeassignedonedonedontheconstructoraturatiddeclaration andcannotBemodifiedifiedifiedifiedifiedifiedifiedifiadtivedabilityattthelanguagelele.2.

See all articles