thinkphp企业付款到零钱,非插件
整理之前有道云笔记时候突然看到17年时候写的,thinkcmf实现企业付款到零钱
class model_tixian
{
//开始操作,传入openid、金额、IP
static function pay_tixian($openid,$money,$tx_orderid,$ip){
$account_api = WeAccount::create();
$setting = uni_setting($_W['uniacid']);
$wxpay = $setting['payment']['wechat'];
$txorder_info = model_adv::getTixianById($tx_orderid);
$nonce_str= self::make_nonce_str();//随机字符串
$partner_trade_no = self::make_partner_trade_no();//商户订单号
//金额改为int类型
$money=$money*100;
$data=array(
'mch_appid'=>'*************************',//商户账号appid
'mchid'=>'*****',//商户号
'nonce_str'=>$nonce_str,//随机字符串
'partner_trade_no'=>$partner_trade_no,//商户订单号
'openid'=>$openid,//用户openid
'check_name'=>'NO_CHECK',//校验用户姓名选项,
're_user_name'=>$txorder_info[0]['name'],//收款用户姓名
'amount'=>$money,//金额
'desc'=>'提现申请',//企业付款描述信息
'spbill_create_ip'=>$ip,//Ip地址
);
$secrect_key='*******';
$data=array_filter($data);
ksort($data);
$str='';
foreach($data as $k=>$v) {
$str.=$k.'='.$v.'&';
}
$str.='key='.$secrect_key;
$data['sign']=md5($str);
$xml=self::arraytoxml($data);
// echo $xml;
$url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
$res=self::curl($xml,$url);
$return=self::xmltoarray($res);
return $return;
// echo getcwd().'/cert/apiclient_cert.pem';die;
}
//生成随机字符串
static function make_nonce_str(){
$chars = md5(uniqid(mt_rand(), true));
$uuid = substr($chars,0,8) ;
$uuid .= substr($chars,8,4) ;
$uuid .= substr($chars,12,4) ;
$uuid .= substr($chars,16,4) ;
$uuid .= substr($chars,20,12);
return $uuid;
// return substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
//创建商户订单号
static function make_partner_trade_no(){
return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
static function unicode() {
$str = uniqid(mt_rand(),1);
$str=sha1($str);
return md5($str);
}
static function arraytoxml($data){
$str='<xml>';
foreach($data as $k=>$v) {
$str.='<'.$k.'>'.$v.'</'.$k.'>';
}
$str.='</xml>';
return $str;
}
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;
}
static function curl($param="",$url) {
$postUrl = $url;
$curlPost = $param;
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl); //抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); // 增加 HTTP Header(头)里的字段
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 终止从服务端进行验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch,CURLOPT_SSLCERT,MODULE_ROOT.'/cert/apiclient_cert.pem'); //这个是证书的位置绝对路径
curl_setopt($ch,CURLOPT_SSLKEY,MODULE_ROOT.'/cert/apiclient_key.pem'); //这个也是证书的位置绝对路径
$data = curl_exec($ch); //运行curl
curl_close($ch);
return $data;
}
}

浙公网安备 33010602011771号