发布日期 :2017-11-22 15:02访问:18次发布IP:219.136.94.19编号:4636966
|
|
- 分 类
- 软件开发
- 单 价
- 电议
- 发货期限
- 自买家付款之日起 3 天内发货
- 有效期至
- 长期有效
- 咨询电话
- 86-010-88889999
- Email
-
2077203314@qq.com
-
让卖家联系我
|
最近张新发换了新的活动,叫集字活动,如果需要开发这个系统的话联系罗大大开发团队:189-2232-7019(微/电)
接下来就是介绍代码的简单流程
public function sendredpack($openid,$money,$trade_no,$act_name){
$config = $this->config;
$data = array(
'nonce_str' => self::getNonceStr(),
'mch_billno' => $trade_no,
'mch_id' => $config['mch_id'],
'wxappid' => $config['wxappid'],
'send_name' => '罗大大',
're_openid' => $openid,
'total_amount' => $money * 100, //付款金额单位为分
'total_num' => 1,
'wishing' => '祝您天天开心!',
'client_ip' => self::getip(),
'act_name' => $act_name,
'remark' => 'From 江南极客'
);
$data['sign'] = self::makeSign($data);
//构造XML数据
$xmldata = self::array2xml($data);
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
//发送post请求
$res = self::curl_post_ssl($url, $xmldata);
if(!$res){
return array('status'=>0, 'msg'=>"Can't connect the server" );
}
// 这句file_put_contents是用来查看服务器返回的结果 测试完可以删除了
//file_put_contents('./log.txt',$res,FILE_APPEND);
$content = self::xml2array($res);
if(strval($content['return_code']) == 'FAIL'){
return array('status'=>0, 'msg'=>strval($content['return_msg']));
}
if(strval($content['result_code']) == 'FAIL'){
return array('status'=>0, 'msg'=>strval($content['err_code']).':'.strval($content['err_code_des']));
}
return $content;
}
public function mchpay($openid,$money,$trade_no,$desc){
$config = $this->config;
$data = array(
'mch_appid' => $config['wxappid'],
'mchid' => $config['mch_id'],
'nonce_str' => self::getNonceStr(),
'partner_trade_no' => $trade_no,
'openid' => $openid,
'check_name'=> 'NO_CHECK', //OPTION_CHECK不强制校验真实姓名, FORCE_CHECK:强制 NO_CHECK:
'amount' => $money * 100, //付款金额单位为分
'desc' => $desc,
'spbill_create_ip' => self::getip()
);
//生成签名
$data['sign'] = self::makeSign($data);
//return $config;
//构造XML数据
$xmldata = self::array2xml($data);
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
//发送post请求
$res = self::curl_post_ssl($url, $xmldata);
if(!$res){
return array('status'=>0, 'msg'=>"Can't connect the server" );
}
// 这句file_put_contents是用来查看服务器返回的结果 测试完可以删除了
//file_put_contents('./log1.txt',$res,FILE_APPEND);
//付款结果分析
$content = self::xml2array($res);
if(strval($content['return_code']) == 'FAIL'){
return array('status'=>0, 'msg'=>strval($content['return_msg']));
}
if(strval($content['result_code']) == 'FAIL'){
return array('status'=>0, 'msg'=>strval($content['err_code']).':'.strval($content['err_code_des']));
}
return $content;
}
这是封装好的类,调用方法也超级简单:
include 'wxmerpay.class.php'; //引入类文件
$config = array(
'wxappid' => 'wx123456789',
'mch_id' => '1123456781',
'pay_apikey' => '1234567898765432123456789',
'api_cert' => $cert_path . '/apiclient_cert.pem',
'api_key' => $cert_path . '/apiclient_key.pem',
'rootca' => $cert_path . '/rootca.pem'
);
$redpack = new WxRedpack($config); //初始化
$redpack->sendredpack($openid,$money,$trade_no,$act_name); //发红包
需要开发找罗大大
|
|
- 地址:上城区环城东路土山一弄2号5211室
- 电话:86-010-88889999
- 联系人:罗大大
开发公司新闻 |