【微信摇一摇红包】签名错误

认真为自己 2016-02-15 03:44:00
实现:
通过摇一摇周边发现普通红包,直接领取。

问题:

在网上找的代码,但是都配置成自己信息后提示“出错了11012”
define("PARTNERKEY", "qwertyuiop12345654321ASDFGHJKLZX");
不知红字部分应该填什么!求大神指点详细!



hbpreorder.php
<?php
/**
*@FileName Lottery.php 红包活动配置
*@Author young
*@version demo1.0.0
*@Email qq1401504121@live.com
**/
//header("Content-type: text/xml");
define("DS",DIRECTORY_SEPARATOR);
define("PARTNERKEY", "qwertyuiop12345654321ASDFGHJKLZX");
define("wxappid", "wx767a963f9af5xxx");//红包提供者公众号的appid
define("send_name", '东方100商厦');//商户名称
define("mch_id", '1248070501');//红包提供者的商户号 微信支付分配的商户号
define("act_name", '摇一摇1');//活动名称
define("auth_mchid", '1000052601');//此处不变 摇周边的授权商户号 官方统一的 1000052601
define("auth_appid", 'wxbf42bd79c4391863');//此处不变 摇周边的授权 官方统一的 appid wxbf42bd79c4391863
define("total_amount", 1);//红包总金额 后面随机
define("total_num", 1);//红包发放总人数
define("wishing", '红包祝福语,展示在红包页面');//红包祝福语,展示在红包页面
define("hb_type", 'NORMAL');//红包类型: GROUP - 裂发红包, (可分享 红包 给好友, 丌建议使用 ) NORMAL - 普通红包
define("remark", 'remark');//备注信息
define("amt_type", 'ALL_RAND');//红包金额设置方式 ALL_RAND — 全 部 随 机
class hbpreorder{
public $hbpreorderUrl='https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder';
private $parameters=array(
'nonce_str' => '',//随机字符串,不长于32位
'sign' => '',//生成签名方式查看
'mch_billno' =>'',//商户订单号 组成: mch_id+yyyymmdd+10位一天内不能重复的数字。
'mch_id' =>'',//红包提供者的商户号 微信支付分配的商户号
'wxappid' => '',//appid
'send_name' => '',//商户名称
'hb_type' => 'NORMAL',//红包类型: GROUP - 裂发红包, (可分享 红包 给好友, 丌建议使用 ) NORMAL - 普通红包
'total_amount' =>'' ,//总金额
'total_num' =>1 ,//红包发放总人数
'amt_type' =>'ALL_RAND',//红包金额设置方式 ALL_RAND — 全 部 随 机
'wishing' => '',//红包祝福语,展示在红包页面
'act_name' =>'' ,//活动名称
'remark' => '',//备注信息
'auth_mchid' =>'' ,//返里请填写 摇周边 的 商户号: 1000052601
'auth_appid' => '',//返里请填写摇周边的 appid:wxbf42bd79c 4391863
'risk_cntl' =>'NORMAL'//
);
function __construct()
{

}
public function init_parameters(){
$this->parameters['nonce_str']=CommonUtil::random_str();
$this->parameters['mch_id']=mch_id;
$this->parameters['wxappid']=wxappid;
$this->parameters['mch_billno']=$this->parameters['mch_id'].date("Ymd").CommonUtil::random_str(10);
$this->parameters['send_name']=send_name;
$this->parameters['hb_type']=hb_type;
$this->parameters['total_amount']=total_amount;
$this->parameters['total_num']=total_num;
$this->parameters['amt_type']=amt_type;
$this->parameters['wishing']=wishing;
$this->parameters['act_name']=act_name;
$this->parameters['remark']=remark;
$this->parameters['auth_mchid']=auth_mchid;
$this->parameters['auth_appid']=auth_appid;
$this->parameters['sign']=$this->get_sign();
}

public function preorder(){
return simplexml_load_string($this->curl_post_ssl($this->hbpreorderUrl,CommonUtil::arrayToXml($this->parameters)),'SimpleXMLElement', LIBXML_NOCDATA);
}

public function setParameter($parameter, $parameterValue) {
$this->parameters[$parameter] = $parameterValue;
$this->parameters['sign']=$this->get_sign();
}
public function getParameter($parameter) {
return $this->parameters[$parameter];
}


function get_sign(){
try {
if (null == PARTNERKEY || "" == PARTNERKEY ) {
throw new SDKRuntimeException("密钥不能为空!" . "<br>");
}
$commonUtil = new CommonUtil();
$unSignParaStr = $commonUtil->formatQueryParaMap($this->parameters, false);
$signStr=$unSignParaStr."&key=".PARTNERKEY;
return strtoupper(md5($signStr));
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}

}

function curl_post_ssl($url, $vars, $second=30,$aHeader=array())
{
$ch = curl_init();
//超时时间
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, '10.206.30.98');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);

//以下两种方式需选择一种
//第一种方法,cert 与 key 分别属于两个.pem文件
curl_setopt($ch,CURLOPT_SSLCERT,getcwd().DS.'cert'.DS.'apiclient_cert.pem');
curl_setopt($ch,CURLOPT_SSLKEY,getcwd().DS.'cert'.DS.'apiclient_key.pem');
curl_setopt($ch,CURLOPT_CAINFO,getcwd().DS.'cert'.DS.'rootca.pem');
//第二种方式,两个文件合成一个.pem文件
//curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/all.pem');

if( count($aHeader) >= 1 ){
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
}

curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$data = curl_exec($ch);
if($data){
curl_close($ch);
return $data;
}
else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
?>



<?php

/**
*@FileName Lottery.php 红包活动配置
*@Author young
*@version demo1.0.0
*@Email qq1401504121@live.com
**/
include_once('CommonUtil.php');
include_once('access_token.php');
include_once('hbpreorder.php');
define("title", "名称");//抽奖活劢名称(选择使用模板时,也作为摇一摇消息主标 题),最长 12 字节
define("desc", "抽奖活劢描述");//抽奖活劢描述(选择使用模板时,也作为摇一摇消息副标 题),最长 14 字节
define("onoff", 1);//抽奖开关。0 关闭,1 开吭,默讣为 1
define("begin_time", '2015-09-18 13:00:00');//抽奖活劢开始时间,unix 时间戳,单位秒
define("expire_time", '2015-09-20 13:00:00');//抽奖活劢结束时间,unix 时间戳,单位秒
define("sponsor_appid", 'wx767a963f9af5f8de');//红包提供商户公众号的 appid
define("total", 20000);//红包总数 此活动的总数
define("jump_url", '');//红包关注界面后可以跳转到第三方自定义的页面 经过测试此项最好为空不可填写
define("key", '52tiandi52tiandi52tiandi52tiandi');//开収者自定义的 key 32位,用来生成活劢抽奖接口的签名参数, 长度 32 位
class Lottery{
private $parameters_addlotteryinfo=array(
'title' => '',
'desc' => '',
'onoff' =>1,
'begin_time' =>'',//抽奖活劢开始时间,unix 时间戳,单位秒
'expire_time' => '',//抽奖活劢结束时间,unix 时间戳,单位秒
'sponsor_appid' => '',
'total' => 0,
'jump_url' =>'' ,
'key' =>''
);
function __construct()
{

}

function init_parameters_addlotteryinfo(){
$this->parameters_addlotteryinfo['title']=title;
$this->parameters_addlotteryinfo['desc']=mch_id;
$this->parameters_addlotteryinfo['onoff']=onoff;
$this->parameters_addlotteryinfo['begin_time']=strtotime(begin_time);
$this->parameters_addlotteryinfo['expire_time']=strtotime(expire_time);
$this->parameters_addlotteryinfo['sponsor_appid']=sponsor_appid;
$this->parameters_addlotteryinfo['total']=total;
$this->parameters_addlotteryinfo['jump_url']=jump_url;
$this->parameters_addlotteryinfo['key']=key;
}

function addlotteryinfo(){
$access_tokenStr=access_token::get_access_token();
$addlotteryinfo_Url="https://api.weixin.qq.com/shakearound/lottery/addlotteryinfo?access_token={$access_tokenStr}&use_template=2";
$arr=CommonUtil::curl_post($addlotteryinfo_Url,json_encode($this->parameters_addlotteryinfo));
print_r($arr);
}

function setprizebucket($lottery_id,$access_tokenStr=''){
$hbpreorder = new hbpreorder();
$hbpreorder->init_parameters();
$hbpreorder->setParameter('total_amount',mt_rand(1, 100));// 1 到100(分)
$hborderinfo=$hbpreorder->preorder();
$hborderinfo=json_decode(json_encode($hborderinfo),true);
file_put_contents('1.log', $hborderinfo);
if(!$access_tokenStr){
$access_tokenStr=access_token::get_access_token();
}
$parameters_setprizebucket=array(
'lottery_id' =>$lottery_id, //之前创建的活动id
'mchid'=>auth_mchid,
'sponsor_appid'=>auth_appid,
'prize_info_list'=>array(array('ticket' =>$hborderinfo[sp_ticket])),
);
//print_r('录入红包请求数据回显:<br>'.json_encode($parameters_setprizebucket));
$setprizebucket_url='https://api.weixin.qq.com/shakearound/lottery/setprizebucket?access_token='.$access_tokenStr;
$arr=CommonUtil::curl_post($setprizebucket_url,json_encode($parameters_setprizebucket));
//print_r('录入红包响应数据回显:<br>'.$arr);
}
public function setParameter_addlotteryinfo($parameter, $parameterValue) {
$this->parameters_addlotteryinfo[$parameter] = $parameterValue;
}
public function getParameter_addlotteryinfo($parameter) {
return $this->parameters_addlotteryinfo[$parameter];
}


function get_sign(){
try {
if (null == key || "" == key ) {
throw new SDKRuntimeException("key不能为空!" . "<br>");
}
$commonUtil = new CommonUtil();
$unSignParaStr = $commonUtil->formatQueryParaMap($this->parameters_addlotteryinfo, false);
$signStr=$unSignParaStr."&key=".key;
return strtoupper(md5($signStr));
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}

}


}

/* 创建红包活动*/
if($_GET['a']=='add'){
$lottery =new Lottery();
$lottery->init_parameters_addlotteryinfo();
$lottery->addlotteryinfo();
}
?>
...全文
429 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
认真为自己 2016-02-16
  • 打赏
  • 举报
回复
太简单了么? 没人愿意回答? 我是开发小白!什么都不懂! 我想学习,没有人出生什么都会!
认真为自己 2016-02-16
  • 打赏
  • 举报
回复
在网上找的代码,但是都配置成自己信息后提示“出错了11012” define("PARTNERKEY", "qwertyuiop12345654321ASDFGHJKLZX"); 不知红字部分应该填什么!求大神指点详细!
认真为自己 2016-02-15
  • 打赏
  • 举报
回复
在网上找的代码,但是都配置成自己信息后提示“出错了11012” define("PARTNERKEY", "qwertyuiop12345654321ASDFGHJKLZX"); 不知红字部分应该填什么!求大神指点详细!

3,143

社区成员

发帖
与我相关
我的任务
社区描述
微信开发即微信公众平台开发,将企业信息、服务、活动等内容通过微信网页的方式进行表现,通过二次开发可以将公众账号由一个媒体型营销工具转化成提供服务的产品。
社区管理员
  • 微信开发
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧