使用Curl和PHP向Blinksky支付API POST数据返回404错误如何解决
问题诊断
你收到404错误的核心原因是请求的URL不匹配官方接口要求:
- 官方明确要求订单接口的请求路径为
POST /send,基础URI拼接后完整请求地址应为https://api.blinksky.com/api/v1/send - 你现有代码中的请求URL仅写了基础URI
https://api.blinksky.com/api/v1,遗漏了末尾的/send路径,因此服务端无法找到对应资源返回404。
修正后的PHP代码
// 仅需修改第一行的请求URL,其余代码无需调整 $url = "https://api.blinksky.com/api/v1/send"; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); $post ='{ "gift": { "action": "order", "apikey": "my-api-key-goes-here", "sender": "Luxury Automotive Inc.", "from": "17705551xxxxxxx", "dest": "16150001xxxxxxx", "code": "62", "amount": 100, "postal": "90211", "msg": "Thanks for the Gift!", "reference": "G62-786", "handle_delivery": false } }'; curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type:application/json' )); curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST'); curl_setopt($ch,CURLOPT_POSTFIELDS, $post); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); var_dump($response); print_r($response);
额外注意事项
- 正式上线时建议将
CURLOPT_SSL_VERIFYPEER和CURLOPT_SSL_VERIFYHOST调整为开启状态,避免出现安全风险 - 代码中的
apikey注意不要泄露,避免被盗用产生损失
内容的提问来源于stack exchange,提问作者Nancy Moore
相关产品推荐
相关产品推荐

