Wechat.php 1.9 KB
<?php


namespace app\api\controller;


use EasyWeChat\Factory;

/**
 * 微信相关
 * @package app\api\controller
 */
class Wechat extends BaseApi
{

    protected $noNeedLogin = '';
    protected $noNeedRight = '*';




    /**
     * jssdk 配置信息
     * @ApiWeigh    (23)
     * @ApiTitle    (jssdk配置信息)
     * @ApiSummary  (jssdk配置信息)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/wechat/wechat_jssdk)
     * @ApiParams   (name="url", type="string", required=true, description="当前地址")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
        'code':'1',
        'msg':'返回成功',
        "data": {
        "jssdk": {
        "debug": false,
        "beta": false,
            "jsApiList": [
                "updateAppMessageShareData",
                "updateTimelineShareData"
            ],
            "appId": "wxa9281176eb57c2f1",
            "nonceStr": "YRPUWx9AaB",
            "timestamp": 1597023466,
            "url": "http://tangyuanji.t.brotop.cn/",
            "signature": "ce924ae62e9cbc7917cee79dafd9d67d31400fcf"
        }
        }
    })
     */
    public function wechat_jssdk()
    {
        $url = $this->request->param('url','');
        if(!$url) {
            $this->error('参数错误');
        }
        $options = get_addon_config('third')['wechat'];
        $options['secret'] = $options['app_secret'];
        $app = Factory::officialAccount($options);
        // 微信jssdk
        $jssdk = $app->jssdk;
        $jssdk->setUrl($url);
        $data = json_decode($jssdk->buildConfig(config('option.apis'), $debug = false, $beta = false, $json = true),true);
        unset($data['beta']);
        unset($data['url']);
        $return = [
            'jssdk' => $data
        ];
        $this->success('成功', $return);
    }

}