Example #1
0
 function download_voice($media_id)
 {
     require_once "jssdk.php";
     $jssdk = new JSSDK("wxe90370e2554fa1d5", "862f2e0b551081b35c0887bcfd3fc978");
     $accesstoken = $jssdk->getAccessToken();
     copy('http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $accesstoken . '&media_id=' . $media_id, 'voices/' . $media_id . '.amr');
     exec('sox --norm voices/' . $media_id . '.amr granular-gh-pages/audio/' . $media_id . '.mp3');
     exec('sox --norm voices/' . $media_id . '.amr granular-gh-pages/audio/sample.mp3');
 }
Example #2
0
<?php

require_once "jssdk.php";
require_once "config.php";
$server_id = $_POST['serverId'];
$jssdk = new JSSDK($wechat_config['appId'], $wechat_config['appSecret']);
$access_token = $jssdk->getAccessToken();
$media_id = $server_id;
$url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$media_id}";
saveMedia($url);
function saveMedia($url)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_NOBODY, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $package = curl_exec($ch);
    $httpinfo = curl_getinfo($ch);
    curl_close($ch);
    $media = array_merge(array('mediaBody' => $package), $httpinfo);
    preg_match('/\\w\\/(\\w+)/i', $media["content_type"], $extmatches);
    $fileExt = $extmatches[1];
    $filename = time() . rand(100, 999) . ".{$fileExt}";
    // make sure the document chmod 777
    file_put_contents($filename, $media['mediaBody']);
    return $filename;
}
echo 'save media success';
Example #3
0
            if ($access_token) {
                $data->expire_time = time() + 7000;
                $data->access_token = $access_token;
                memcache_set($this->mmc, 'access_token', json_encode($data));
            }
        } else {
            $access_token = $data->access_token;
        }
        return $access_token;
    }
    private function httpGet($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
}
$obj = new JSSDK('Your APP_ID', 'Your APP_SECRIET');
$access_token = $obj->getAccessToken();
//echo $access_token;
//$ticket = $obj->getJsApiTicket();
//echo $ticket;exit;
$url = $_REQUEST['url'];
$ticket = $obj->getSignPackage($url);
echo json_encode($ticket);
Example #4
0
<?php

require_once "jssdk.php";
$jssdk = new JSSDK("YOURWEBID", "YOURSECRET");
$signPackage = $jssdk->getAccessToken();
echo "success";
?>