123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace app\common\library;
- use app\common\model\Config;
- use think\Controller;
- class Hecheng extends Controller
- {
-
- public function hecheng($money,$pay_type){
-
- $apiKey = "9sjcD2OQB71wBwGMEdGOvh2l";
- $secretKey = "j4VzpHUmraneN6wNCiSx3lkMKoNXWa0X";
- if ($pay_type=='weixin' || $pay_type=='yue'){
- $text = "全民创商家微信收款".$money."元。";
- }elseif ($pay_type=='zfb'){
- $text = "全民创商家支付宝收款".$money."元。";
- }
- $text2 = iconv("UTF-8", "GBK", $text);
- $per = 0;
- $spd = 4;
- $pit = 5;
- $vol = 6;
- $aue = 3;
- $formats = array(3 => 'mp3', 4 => 'pcm', 5 =>'pcm', 6 => 'wav');
- $format = $formats[$aue];
- $cuid = time();
-
- $auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=".$apiKey."&client_secret=".$secretKey;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $auth_url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_VERBOSE, false);
- $res = curl_exec($ch);
- if(curl_errno($ch))
- {
- print curl_error($ch);
- }
- curl_close($ch);
- $response = json_decode($res, true);
- if (!isset($response['access_token'])){
- echo "ERROR TO OBTAIN TOKEN\n";
- exit(1);
- }
- if (!isset($response['scope'])){
- echo "ERROR TO OBTAIN scopes\n";
- exit(2);
- }
- if (!in_array('audio_tts_post',explode(" ", $response['scope']))){
- echo "DO NOT have tts permission\n";
-
- exit(3);
- }
- $token = $response['access_token'];
-
-
- $params = array(
- 'tex' => urlencode($text),
- 'per' => $per,
- 'spd' => $spd,
- 'pit' => $pit,
- 'vol' => $vol,
- 'aue' => $aue,
- 'cuid' => $cuid,
- 'tok' => $token,
- 'lan' => 'zh',
- 'ctp' => 1,
- );
- $paramsStr = http_build_query($params);
- $url = 'http://tsn.baidu.com/text2audio';
- $urltest = $url . '?' . $paramsStr;
-
- return $urltest;
-
-
- $g_has_error = true;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt ($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $paramsStr);
- function read_header($ch, $header){
- global $g_has_error;
- $comps = explode(":", $header);
-
-
- if (count($comps) >= 2){
- if (strcasecmp(trim($comps[0]), "Content-Type") == 0){
- if (strpos($comps[1], "audio/") > 0 ){
- $g_has_error = false;
- }else{
- echo $header ." , has error \n";
- }
- }
- }
- return strlen($header);
- }
-
- $data = curl_exec($ch);
- if(curl_errno($ch))
- {
- echo curl_error($ch);
- exit(2);
- }
- curl_close($ch);
- echo $urltest . "\n";
- die;
- $file = $g_has_error ? "result.txt" : "result." . $format;
- file_put_contents($file, $data);
- echo "\n$file saved successed, please open it \n";
- }
- }
|