网上很多的对接其他网站的接口的代码,每次都需要百度现找,而且不一定合适,找到一份合适的,记录一下
- public function fun()
- {
- //进行一些事前的逻辑业务运算
-
- /*同步*/
- header('Content-type:text/html;charset=utf-8');
-
- //要请求访问的地址
- $url = "";
-
- $method = "POST";
-
- //拼接要传递的参数
- $params = "order_id=".$order->id."&order_time=".date("Y-m-d H:i:s", time())."&original_merchant_id=".$card_id."&order_sn=".$order->order_no."&merchant_name=".$card['title']."&reality_money=".$origina."&behind_preferrence=".$price."&status=1&coupon=".$order->coupon_discount_price."&phone=".$user['mobile'];
-
-
-
- $header = array();
- $header[] = 'User-Agent: Apipost client Runtime/+https://www.apipost.cn/';
- $header[] = 'Content-Type: application/x-www-form-urlencoded';
-
-
- $content = $this->linkcurl($url,$method,$params,$header);
-
- $result = json_decode($content,true);
-
- //拿到返回接口,然后进行数据处理
- }
-
-
- public function linkcurl($url,$method,$params=false,$header=false)
- {
- $httpInfo = array();
- $ch = curl_init();
-
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_FAILONERROR, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- if (1 == strpos("$".$url, "https://"))
- {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- }
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-
- if($method == "POST" ){
- curl_setopt( $ch , CURLOPT_POST , true );
- curl_setopt( $ch , CURLOPT_POSTFIELDS,$params);
- }else if($params){
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.http_build_query($params) );
- }
- $response = curl_exec( $ch );
- if ($response === FALSE) {
- //echo "cURL Error: " . curl_error($ch);
- return false;
- }
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
- curl_close( $ch );
- return $response;
-
-
-
- }