1

我在php中有以下代码:

define("TOKEN_URL", "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");



 $arrData = array(
                'grant_type=client_credentials',
                'client_id='.CLIENT_ID,
                'client_secret='.urlencode(ACCESS_KEY),
                'scope=urn%3aWindowsAzureMediaServices'
            );


            $arrHeader = array(
                'Content-length:'.strlen($this->generateData($arrData))
            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
            curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $data = curl_exec($ch);
            curl_close($ch);
            $arrToken = json_decode($data);

我无法获取令牌代码。请任何人都可以检查什么可能是错的?

4

1 回答 1

1

可能有几个问题:

  1. 您可以简化一些事情并使用http_build_query()

    $data = http_build_query(array(
        'grant_type' => 'client_credentials',
        'client_id' => CLIENT_ID,
        'client_secret' => ACCESS_KEY,
        'scope' => 'urn:WindowsAzureMediaServices',
    ));
    $ch = curl_init(TOKEN_URL);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if (($res = curl_exec($ch)) === false) {
        die(curl_error($ch));
    }
    $arrToken = json_decode($res);
    
  2. 如果出现错误,首先要确定您是否有更新的 CA 证书列表

于 2013-02-19T12:22:58.440 回答