微信 付款到零钱
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信 付款到零钱相关的知识,希望对你有一定的参考价值。
require_once "include/lib/Api.class.php";require_once "include/lib/JsApiPay.class.php";
require_once "include/lib/PayNotifyCallBack.class.php";
require_once "include/lib/Config.class.php";
require_once "include/lib/JSSDK.class.php";
class WeiPay
{
//企业向个人付款
public static function payToUser($data)
{
//微信付款到个人的接口 前4个参数,去微信平台获取
$url = ‘https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers‘;
$params["mch_appid"] = ‘wxed179f31e9bd43**‘; //公众账号appid
$params["mchid"] = ‘153660**11‘; //商户号 微信支付平台账号
$params[‘key‘] = ‘8ffbb9de88a5****edd1a14858b0‘; //对应的商户号的key 秘钥
$params["nonce_str"] = ‘aedwnewe‘.mt_rand(100,999); //随机字符串
$params["partner_trade_no"] = mt_rand(10000000,99999999); //商户订单号
$params["amount"] = $data[‘pay_amount‘]; //金额
$params["desc"] = $data[‘order_title‘]; //企业付款描述
$params["openid"] = $data[‘openID‘]; //用户openid
$params["check_name"] = ‘NO_CHECK‘; //不检验用户姓名 固定值 可以
$params[‘spbill_create_ip‘] = ‘101.37.163.73‘; //获取IP 服务器ip
//生成签名(签名算法后面详细介绍)
$str = ‘amount=‘.$params["amount"].‘&check_name=‘.$params["check_name"].‘&desc=‘.$params["desc"].
‘&mch_appid=‘.$params["mch_appid"].‘&mchid=‘.$params["mchid"].‘&nonce_str=‘.$params["nonce_str"].
‘&openid=‘.$params["openid"].‘&partner_trade_no=‘.$params["partner_trade_no"].‘&spbill_create_ip=‘.
$params[‘spbill_create_ip‘].‘&key=‘.$params[‘key‘];
//md5加密 转换成大写
$sign = strtoupper(md5($str));
$params["sign"] = $sign;//签名
$xml = self::arrayToXml($params);
return self::curl_post_ssl($url, $xml);
}
//遍历数组方法
public static function arraytoxml($data){
$str=‘<xml>‘;
foreach($data as $k=>$v) {
$str.=‘<‘.$k.‘>‘.$v.‘</‘.$k.‘>‘;
}
$str.=‘</xml>‘;
return $str;
}
public static function xmltoarray($xml) {
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, ‘SimpleXMLElement‘, LIBXML_NOCDATA);
$val = json_decode(json_encode($xmlstring),true);
return $val;
}
//上个方法中用到的curl_post_ssl()
public static function curl_post_ssl($url, $vars, $second = 30, $aHeader = array())
{
$isdir = "/www/wwwroot/qbb/tapi/storage/cert/";//证书位置
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 终止从服务端进行验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
curl_setopt($ch, CURLOPT_SSLCERTTYPE, ‘PEM‘);//证书类型
curl_setopt($ch, CURLOPT_SSLCERT, $isdir . ‘apiclient_cert.pem‘);//证书位置
curl_setopt($ch, CURLOPT_SSLKEYTYPE, ‘PEM‘);//CURLOPT_SSLKEY中规定的私钥的加密类型
curl_setopt($ch, CURLOPT_SSLKEY, $isdir . ‘apiclient_key.pem‘);//证书位置
curl_setopt($ch, CURLOPT_CAINFO, ‘PEM‘);
curl_setopt($ch, CURLOPT_CAINFO, $isdir . ‘rootca.pem‘);
if (count($aHeader) >= 1) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
}
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部数据使用HTTP协议中的"POST"操作来发送
$data = curl_exec($ch);//执行回话
if ($data) {
curl_close($ch);
$res = self::xmltoarray($data);
return $res;
} else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
注意:
1,金额必须是整数,最低是30=3毛钱
2,用公众号的APPID,对应的商户号 和key秘钥
3,对应的公众号的openID
以上是关于微信 付款到零钱的主要内容,如果未能解决你的问题,请参考以下文章