💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` <? $url = 'http://154.221.25.18:1000/api/address'; $app_name = 'test'; $key = 'test123'; //请求参数 $data['app_name']=$app_name; $data['symbol']='eth'; $data['nonce']=uniqid(); //对请求参数进行签名 $data['sign']=MakeSign($data,$key); //转换为json数据 $params = json_encode($data); //发送post $return = send_post($url,$params); //打印结果 var_dump($return); /** * 发送post * @param $url 网关地址 * @param $post_data POST数据json形式 */ function send_post($url, $post_data) { $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/json', 'content' => $post_data, 'timeout' => 15 * 60 // 超时时间(单位:s) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } /** * 生成签名 * @param $value 参数数组 * @param $key 密钥 */ function MakeSign($value,$key){ //签名步骤一:按字典序排序参数 ksort($value); $string = ToUrlParams($value); //签名步骤二:在string后加入KEY $string = $string . "&key=".$key; //签名步骤三:MD5加密或者HMAC-SHA256 $string = md5($string); //签名步骤四:所有字符转为大写 $result = strtoupper($string); return $result; } /** * 格式化参数格式化成url参数 * $value 参数数组 */ function ToUrlParams($value){ $buff = ""; foreach ($value as $k => $v) { if($k != "sign" && $v != "" && !is_array($v)){ $buff .= $k . "=" . $v . "&"; } } $buff = trim($buff, "&"); return $buff; } ```