标签:没有 msi wal ring back price test art url参数
第一步先到stripe 官网 https://stripe.com 注册一个账号
然后到 https://pan.baidu.com/s/1eRIVVGm 这个链接里面下载例子(这个文件里只包含支付demo和公共api接口包)
Api 接口地址 :https://stripe.com/docs/api (这个地址可能在谷歌里面打开里面什么都没有,大家可以到火狐或者IE浏览器上看看),api地址里面包含各种有关支付、退款的例子,大家可以自己看看如果不想看的话可以直接用我发的。
退款:退款里面调用的文件在 https://pan.baidu.com/s/1eRIVVGm 这里面
/*
* 退款测试
*/
public function refund(){
require_once ‘public/stripe-php-3.20.0/init.php‘;
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
$re = \Stripe\Refund::create(array(
"charge" => "ch_18lF8dEm2C3rQ9STPtScvnth",
"amount" => "50",
));
echo "<pre>";
var_dump($re);die;
}
支付宝官网demo地址:https://b.alipay.com/order/techService.htm
打开连接后在最下面有所有的demo
/**
* 支付宝退款
*/
function alipayapi(){
header("Content-type: text/html; charset=utf-8");
require_once ‘public/refund/alipay.config.php‘;
require_once ‘public/refund/lib/alipay_submit.class.php‘;
/**************************请求参数**************************/
//批次号,必填,格式:当天日期[8位]+序列号[3至24位],如:201603081000001
$batch_no = date(‘Ymd‘,time()).time();
//退款笔数
$batch_num = 1;
//必填,参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的数量999个)
//退款详细数据 2011011201037066^5.00^协商退款
$detail_data = "2016051821001004370254817579^0.01^协商退款";
/************************************************************/
//构造要请求的参数数组,无需改动
$parameter = array(
"service" => trim($alipay_config[‘service‘]),
"partner" => trim($alipay_config[‘partner‘]),
"notify_url" => trim($alipay_config[‘notify_url‘]),
"seller_user_id" => trim($alipay_config[‘seller_user_id‘]),
"refund_date" => trim($alipay_config[‘refund_date‘]),
"batch_no" => $batch_no,
"batch_num" => $batch_num,
"detail_data" => $detail_data,
"_input_charset" => trim(strtolower($alipay_config[‘input_charset‘]))
);
//建立请求
$alipaySubmit = new \AlipaySubmit($alipay_config);
// echo "<pre>";
// var_dump($alipaySubmit);die;
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认");
echo $html_text;
}
/*
* 订单退款
*/
static function wx_tui($order_id,$order){
// 引入微信api
require_once "./api/wxpay/lib/WxPay.Api.php";
$input = new \WxPayRefund();
$input->SetTransaction_id($order_id);
$input->SetTotal_fee(1);
$input->SetRefund_fee(1);
$input->SetOut_refund_no(\WxPayConfig::MCHID . date("YmdHis"));
$input->SetOp_user_id(\WxPayConfig::MCHID);
$result = \WxPayApi::refund($input);
// var_dump($result);
// F(‘wxrefund‘ . setName(), $result);
// 更新退款信息
if ($result[‘return_code‘] == "SUCCESS")
{
$time = time();
// 更新订单状态
M("order")->where("order_id = {$order[‘order_id‘]}")
->save(array(‘refund_price‘=>$order[‘total_price‘],
‘user_confirm_refund‘=>1,
‘refund_status_time‘=>$time,
‘refund_status‘=>1,
‘pay_status‘=>6));
// M("orders")->where(array("trade_no" => $trade))->save($saveData);
}
}
微信提现的前提需要开启
功能
//微信提现
public function wxtix(){
$date[‘device_info‘] = post("access_token");//微信支付分配的终端设备号
$date[‘openid‘] = post("openid");//商户appid下,某用户的openid
$date[‘amount‘] = post("money",1);//企业付款金额,单位为分
$user_id = (int)post("user_id");
ksort($date);
$string = $this->ToUrlParams($date);
$string = substr(md5(‘kaimi‘.$string."kaimi"),8,16);
$secret = post("secret",‘‘);//加密字段
if($string!=$secret){
$this->showCode(-2, array());
}
$user_wallet = M("user_wallet")->where("user_id = {$user_id}")->find();
if($user_wallet[‘wallet_money‘]<$date[‘amount‘]){
$this->showCode(1, array(), ‘余额不足‘);
}
if(empty($date[‘device_info‘])||empty($date[‘openid‘])||empty($date[‘amount‘])){
$this->showCode(-1, array(), ‘参数缺少‘);
}
$date[‘partner_trade_no‘] = "ti".time(). rand(10000, 99999);//商户订单号,需保持唯一性
$date[‘amount‘] = $date[‘amount‘] * 100;
$time = time();
M("titrade_no")->add(array("user_id"=>$user_id,"type"=>2,"money"=>$date[‘amount‘]/100,"trade_no"=>$date[‘partner_trade_no‘],"ctime"=>$time));
$data = $this->wx_tixian($date);
if($data[‘return_code‘]==‘SUCCESS‘||$data[‘result_code‘]==‘SUCCESS‘){
M("user_wallet")->where("user_id = {$user_id}")->setDec("wallet_money",$date[‘amount‘]/100);
$time = time();
M("titrade_no")->where("trade_no = {$data[‘partner_trade_no‘]} and user_id = {$user_id}")->save(array(‘ti_time‘=>$time,‘status‘=>1));
$this->showCode(0, array(), ‘提现成功‘);
}else{
$this->showCode(1, array(), ‘提现失败‘);
}
}
/**
* @param $date
* 生成签名
*/
public function sign($date){
//签名步骤一:按字典序排序参数
ksort($date);
$string = $this->ToUrlParams($date);
//签名步骤二:在string后加入KEY
$string = $string . "&key=".\WxPayConfig::KEY;
//签名步骤三:MD5加密
$string = md5($string);
//签名步骤四:所有字符转为大写
$result = strtoupper($string);
return $result;
}
/**
* 格式化参数格式化成url参数
*/
public function ToUrlParams($date)
{
$buff = "";
foreach ($date as $k => $v)
{
if($k != "sign" && $v != "" && !is_array($v)){
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
//生成XML
function xml($arr){
$str = "<xml>";
foreach($arr as $k=>$v){
$str .= "<{$k}>{$v}</{$k}>";
}
$str .= "</xml>";
return $str;
}
/*
* 微信提现
*/
public function wx_tixian($data){
header("Content-type: text/html; charset=utf-8");
// 引入微信api
require_once "./api/wxpay/lib/WxPay.Api.php";
$date[‘mch_appid‘] = \WxPayConfig::APPID;//微信分配的公众账号ID(企业号corpid即为此appId)
$date[‘mchid‘] = \WxPayConfig::MCHID; //微信支付分配的商户号
$date[‘nonce_str‘] = ‘kaimi‘ .time(). rand(10000, 99999); //随机字符串,不长于32位
$date[‘partner_trade_no‘] = "ti".time(). rand(10000, 99999);//商户订单号,需保持唯一性
/**
* NO_CHECK:不校验真实姓名
*FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账)
*OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
*/
$date[‘check_name‘] = "NO_CHECK";
$date[‘re_user_name‘] = ""; //收款用户真实姓名。 如果check_name设置为FORCE_CHECK或OPTION_CHECK,则必填用户真实姓名
$date[‘desc‘] = "提现"; //企业付款操作说明信息。必填。
$date[‘spbill_create_ip‘] = $_SERVER["REMOTE_ADDR"]; //调用接口的机器Ip地址
$date[‘sign‘] = $this->sign($date); //签名
$data = $this->xml($date);
$ch = curl_init();
$MENU_URL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
curl_setopt($ch, CURLOPT_URL, $MENU_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$zs1 = \WxPayConfig::getSSLcertPath();
$zs2 = \WxPayConfig::getSSLKeyPath();
curl_setopt($ch, CURLOPT_SSLCERT, $zs1);
curl_setopt($ch, CURLOPT_SSLKEY, $zs2);
// curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01;
// Windows NT 5.0)‘);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$info = curl_exec($ch);
if (curl_errno($ch)) {
echo ‘Errno‘ . curl_error($ch);
}
curl_close($ch);
$data = \WxPayResults::Init($info);
return $data;
}
微信官网接口地址:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
/**
* 帮我买下单 微信支付
*/
public function weipay(){
$order_id = I("order_id");
$money = I("money");
if($order_id == ‘‘ || $money == ‘‘){
$this->json("100090","缺少参数");
}
require_once "./public/weipay/lib/WxPay.Api.php";
require_once "./public/weipay/example/log.php";
require_once "./public/weipay/lib/WxPay.Config.php";
$ordrTitle = "电达人订单支付";
// 准备参数
$notify_url = $_SERVER[‘HTTP_HOST‘]."/index.php/api/orders/order_callback_weipay";
// 统一下单
$input = new \WxPayUnifiedOrder();
$input->SetBody($ordrTitle);
$input->SetAttach($ordrTitle);
$input->SetOut_trade_no($order_id);
$input->SetTotal_fee($money * 100);
$input->SetTime_start(date("YmdHis"));
$input->SetNotify_url($notify_url);
$input->SetTrade_type("APP");
$input->SetSpbill_create_ip($_SERVER[‘REMOTE_ADDR‘]);//终端ip
$order = \WxPayApi::unifiedOrder($input);
//dump($order);die;
if ($order[‘return_code‘] == ‘SUCCESS‘)
{
$wxvalue = array();
$wxvalue[‘appid‘] = $order[‘appid‘];
$wxvalue[‘prepayid‘] = $order[‘prepay_id‘];
$wxvalue[‘partnerid‘] = $order[‘mch_id‘];
$wxvalue[‘package‘] = ‘Sign=WXPay‘;
$wxvalue[‘timestamp‘] = time();
$wxvalue[‘noncestr‘] = \WxPayApi::getNonceStr();
ksort($wxvalue); // 排序
$wxstr = $this->ToUrlParams($wxvalue);
$string = $wxstr . "&key=" . \WxPayConfig::KEY;
// 签名步骤三:MD5加密
$md5string = md5($string);
$wxvalue[‘sign‘] = strtoupper($md5string);
$wxvalue[‘title‘] = $ordrTitle;
$new = $wxvalue;
$new[‘order_id‘] = $order_id;
//dump($new);die;
$this->json(‘10001‘,$new);
// json("10001", $wxvalue);
}else{
$this->json(‘405‘, ‘支付生成失败,请联系我们‘);
}
}
/**
* 微信支付回调
*/
public function order_callback_weipay(){
$arr = $_POST;
if (empty($arr))
{
$xml = file_get_contents(‘php://input‘);
$arr = $this->FromXml($xml);
}
if (array_key_exists(‘openid‘, $arr))
{
if($arr[‘result_code‘]=="SUCCESS"){
$orderid = $arr[‘out_trade_no‘];
$stas = M("order")->where("order_id=‘$orderid‘")->field("statics")->find();
$static = $stas["statics"];
if($static == 2){
$da["statics"] = 3;
$da["is_zhi"] = 1;
} else {
$da["statics"] = 9;
$da["is_zhi"] = 2;
}
M("order")->where("order_id = {$arr[‘out_trade_no‘]}")->save($da);
}
//$info = json_decode($arr,true);
// M("weixin")->add($arr);
//echo ‘<xml><return_code>SUCCESS</return_code><return_msg>OK</return_msg></xml>‘;
echo "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
}
}
/**
* 拼接key=>$value
* @access public
*/
protected function ToUrlParams ($wxarr)
{
$buff = "";
foreach ($wxarr as $k => $v)
{
if ($k != "sign" && $v != "" && ! is_array($v))
{
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
* xml数据转array
* @param unknown $xml
* @throws WxPayException
* @return mixed
*/
protected function FromXml ($xml)
{
if (! $xml)
{
return;
}
// 将XML转为array
// 禁止引用外部xml实体
libxml_disable_entity_loader(true);
$data = json_decode(json_encode(simplexml_load_string($xml, ‘SimpleXMLElement‘, LIBXML_NOCDATA)), true);
return $data;
}
微信官网demo地址 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1
第三方技术 支付 退款
标签:没有 msi wal ring back price test art url参数
原文地址:http://www.cnblogs.com/jhy-ocean/p/6076843.html