根据支付文档找到funpay api的支付接口,选择你的开发语言,按上面的代码流程复制下来调试就行了。(复制代码的时候选择英文,否则代码可能会出现中文标点符号等其他编译问题导致报错)
一. 支付代码:
<?php
//创建fgkey。
// 请将商户信息值定义为您收到的值。(如果使用示例值,将发生 400 错误。)
$mID = "" ; //你的商户id
$secretKey = "" ; //你的商户密钥
$openId = ''; //若微信支付,则须传openid
//微信支付商品的信息数据结构
$order_data = "{
'goods_detail': [
{
'goods_name': '$goods_name',
'quantity': '$number'
}
]
}";
//请将支付页面通过表单接收的参数配置成数组。
$paramArray [ "ver" ] = "V2" ;
$paramArray [ "mid" ] = $mID ;
// $paramArray [ "mname" ] = "" ;
$paramArray [ "servicetype" ] = "S001"; //支付宝S000,微信S001
$paramArray [ "refno" ] = ""; //你的订单支付码
$paramArray [ "reqcur" ] = "KRW" ; //你的支付币种
$paramArray [ "reqamt" ] = ""; //商品价格
$paramArray [ "buyername" ] = ""; //下单人姓名
// $paramArray [ "tel" ] = '';//"010-1004-1004" ;
// $paramArray [ "email" ] = '';//"test@icbnet.co.kr" ;
$paramArray [ "product" ] = ""; //商品名称
$paramArray [ "trade_information" ] = $order_data ;
$paramArray [ "refer_url" ] = "" ; //支付完成url
$paramArray [ "returnurl" ] = "" ; //付款通知页面网址
$paramArray [ "statusurl" ] = ''; //支付成功回调地址
$paramArray [ "param1" ] = $openId ;
$paramArray [ "reqtype" ] = $reqtype; //P:PC端、M:移动端(或H5)、A:APP、J:JSAPI、N:小程序
$paramArray [ "restype" ] = "JSON" ; // 因为设置为JSON是为了接收服务器的请求响应,所以设置为PAGE才能转到实际的支付页面。
$fgkey_data = CourseOrder::getFgkey($paramArray,$secretKey);
/*
* ########################################################
* 2. 请求 Funpay 付款批准。(POST)
* ########################################################
*/
// 在现有参数的基础上额外定义 fgkey。
$postParamData = $fgkey_data['mergeParamText'] . "&fgkey=" . $fgkey_data['text_d'] ;
// 如果直接从服务器发送,多语言值可能会损坏,因此请对其进行编码。
$postParamData = str_replace ( "buyername=".$user_name , "buyername=" . urlencode ( "$user_name" ) , $postParamData ) ;
$postParamData = str_replace ( "product=".$product , "product=" . urlencode ( "$product" ) , $postParamData ) ;
// echo 'postData:'. $postParamData . "\n" ;
// 设置POST请求的连接信息。
$funpayCon = curl_init ( ) ;
$funpayConHeader [ ] = "Content-Type: application/x-www-form-urlencoded; text/html; charset=utf-8" ;
$funpayConHeader [ ] = "Content-Length: " . strlen ( $postParamData ) ;
curl_setopt ( $funpayCon , CURLOPT_URL , "https://onlinetest.funpay.co.kr/payment/payment.icb" ) ;
curl_setopt ( $funpayCon , CURLOPT_BINARYTRANSFER , true ) ;
curl_setopt ( $funpayCon , CURLOPT_POST , 1 ) ;
curl_setopt ( $funpayCon , CURLOPT_POSTFIELDS , $postParamData ) ;
curl_setopt ( $funpayCon , CURLOPT_RETURNTRANSFER , 1 ) ;
curl_setopt ( $funpayCon , CURLOPT_HTTPHEADER , $funpayConHeader ) ;
curl_setopt ( $funpayCon , CURLOPT_VERBOSE , true ) ;
curl_setopt ( $funpayCon , CURLOPT_SSL_VERIFYPEER , false ) ;
// Proceed with the POST request.
$funpayCallResult = curl_exec ( $funpayCon ) ;
// Check the HTTP communication result.
$resHttpCode = curl_getinfo ( $funpayCon , CURLINFO_HTTP_CODE ) ;
// Close the curl session and release the resources.
curl_close ( $funpayCon ) ;
// 解析返回结果
$result = json_decode($funpayCallResult, true);
if($result && isset($result['rescode'])) {
if($result['rescode'] == '0000') {
$encodedStr = $result['resmsg'];
$jsonStr = urldecode($encodedStr); // URL解码
$data = json_decode($jsonStr, true); // 转为PHP数组
$data['tradeNo'] = $order_trade_no;
self::where('id',$order_id)->update(['transid' => $result['transid']]);
return $data;
}
}else{
return '支付失败';
}
二 . 开发注意点:
1. 在平台复制代码模板时,选择英文,否则会因为翻译导致代码错乱而报错。
2. 选择你需要的支付方式,以及对应他提供的产品参数格式。
3. 若微信支付,则须多穿一个数据参数,为会员的openid。
4.返回结果就是微信平台统一下单页所获取的参数信息,直接返回给前端让他吊起微信支付就可以了。
5. 要有什么疑问,可发邮件咨询他们技术支持,就是回复有点慢。