您的位置:首页 > 其它

支付宝七(商户会员卡之发放卡券)

2016-12-13 15:56 176 查看
  支付宝会员卡发放 接口实现 部分功能

1. 发放会员卡

# 会员卡 开卡
public function openCard(){
$this->load->helper('url');
$access_token = $this->session->userdata('access_token');
#如果缓存已存在 直接返回 之前的跳转地址
if(!$access_token){
$this->alipay_auth();
}
$this->AopClient->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$this->AopClient->apiVersion = '1.0';
$request = new AlipayMarketingCardOpenRequest();
$post_data['out_serial_no'] = 'E201611250222479XXX';
$post_data['card_template_id'] = '20161207000000000103117000300XXX';
$post_data['card_user_info'] = array(
'user_uni_id'=> '2088502948697XXX',
'user_uni_id_type'=>'UID'
);
$card_no = 'ALICARD00002';
$post_data['card_ext_info'] = array(
'biz_card_no' => 'hha',#支付宝业务卡号 说明: 1、开卡成功后返回该参数,需要保存留用; 2、开卡/更新/删卡/查询卡接口请求中不需要传该参数;
'external_card_no'=>$card_no, # 商户外部会员卡卡号 说明: 1、会员卡开卡接口,如果卡类型为外部会员卡,请求中则必须提供该参数; 2、更新、查询、删除等接口,请求中则不需要提供该参数值;
'open_date' => date('Y-m-d H:i:s'),
'valid_date' => date('2022-m-d H:i:s'),
'level' =>'VIP1',
'point' => '88',
'balance' => '128.88'
);
$post_data = json_encode($post_data,JSON_UNESCAPED_UNICODE);
$request->setBizContent($post_data);
$result = $this->AopClient->execute($request,$access_token);
#echo json_encode($result,JSON_UNESCAPED_UNICODE);
#echo $access_token;exit;
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}
}
授权部分,参见
网页授权获取用户信息

返回结果

{"code":"10000","msg":"Success","card_info":{"balance":"128.88","biz_card_no":"lsh0000000xxx","external_card_no":"ALICARD000xx","level":"VIP1","open_date":"2016-12-12 17:19:05","point":"88","valid_date":"2022-12-12 17:19:05"}}

2. 更新会员卡

#卡券 更新
# 请注意 $post_data['target_card_no'] 和$post_data['card_info']['external_card_no'] 必须和原来开卡时一致 否则会报会员卡不存在
public function updateCard(){
$this->AopClient->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$this->AopClient->apiVersion = '1.0';
$request = new AlipayMarketingCardUpdateRequest();
$post_data['target_card_no'] = 'lsh000000057x';
$post_data['target_card_no_type'] = 'BIZ_CARD';
$post_data['occur_time'] = date('Y-m-d H:i:s');
$card_no = 'ALICARD00XXX';
$post_data['card_info'] = array(
'biz_card_no' => 'hha',#支付宝业务卡号 说明: 1、开卡成功后返回该参数,需要保存留用; 2、开卡/更新/删卡/查询卡接口请求中不需要传该参数;
'external_card_no'=> $card_no, # 商户外部会员卡卡号 说明: 1、会员卡开卡接口,如果卡类型为外部会员卡,请求中则必须提供该参数; 2、更新、查询、删除等接口,请求中则不需要提供该参数值;
'open_date' => date('Y-m-d H:i:s'),
'valid_date' => date('2022-m-d H:i:s'),
'level' =>'VIP2',
'point' => '188',
'balance' => '1128.88'
);
$post_data = json_encode($post_data,JSON_UNESCAPED_UNICODE);
$request->setBizContent($post_data);
$result = $this->AopClient->execute($request);

$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}
}
返回结果

3. 查询会员卡

#卡券 查询
public function queryCard(){
$this->AopClient->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$this->AopClient->apiVersion = '1.0';
$request = new AlipayMarketingCardQueryRequest();
$post_data['target_card_no'] = 'lsh00000005XX';
$post_data['target_card_no_type'] = 'BIZ_CARD';
$post_data['card_user_info'] = array( #√ 可选参数
'user_uni_id'=> '20885029486XXXX',
'user_uni_id_type'=>'UID'
);
$request->setBizContent(json_encode($post_data));
$result = $this->AopClient->execute($request);

$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}
}
返回结果

array(1) { [0]=> object(stdClass)#27 (2) { ["alipay_marketing_card_query_response"]=> object(stdClass)#28 (4) { ["code"]=> string(5) "10000" ["msg"]=> string(7) "Success" ["card_info"]=> object(stdClass)#29 (7) { ["balance"]=> string(7) "1128.88" ["biz_card_no"]=> string(13) "lsh0000000xxx" ["external_card_no"]=> string(12) "ALICARD000xx" ["level"]=> string(4) "VIP2" ["open_date"]=> string(19) "2016-12-13 14:41:38" ["point"]=> string(3) "188" ["valid_date"]=> string(19) "2022-12-13 14:41:38" } ["schema_url"]=> string(63) "alipays://platformapi/startapp?appId=20000021&b=m&p=10606450079" } ["sign"]=> string(172) "LMyk18n2vKskbPRLyLvaxq0LJiM9OV4coFsgyLs6EPfhmMT2kU92e+xC1sW3o44EYsbJdN6J6BVz3Z/eiBAOYKQ01y4CdYs6idLlepiGTvZjkldXzNfe5Rc2VUsqPctI3rNgcWlZCeNUWgnRoQaBnH1xnYq6g72u/fKpEOYaXO0=" } }

4. 删除会员卡

#卡券 删除
public function deleteCard(){
$this->AopClient->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$this->AopClient->apiVersion = '1.0';
$request = new AlipayMarketingCardDeleteRequest();
$post_data['out_serial_no'] = date('YmdHis').mt_rand(100,999); #商户端删卡业务流水号(商户确保流水号唯一性)
$post_data['target_card_no'] = 'lsh0000000XXX';
$post_data['target_card_no_type'] = 'BIZ_CARD';
$post_data['reason_code'] = 'USER_UNBUND'; # 删卡原因 USER_UNBUND:用户解绑(可以重新绑定) CANCEL:销户(完成销户后,就不能再重新绑定) PRESENT:转赠(可以重新绑定)
#$post_data['ext_info'] = ''; #√ 可选参数 目前支持如下key: new_card_no:新卡号 donee_user_id:受赠人userId 如 {"new_card_no":"12345"," donee_user_id":"20881021306XX"}
$request->setBizContent(json_encode($post_data));
$result = $this->AopClient->execute($request);
var_dump(json_encode($result,JSON_UNESCAPED_UNICODE));exit;
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}
}

返回结果
{"alipay_marketing_card_delete_response":{"code":"10000","msg":"Success"},"sign":"PK9mGX8uy3xfwRKygPxPCuf62YQU5JrdY4yDSn5dRhRcjtcTlzm8Gzv1yhnNXOhyITDzY6O8+rwPpSUqrQXT3VvS6dkMvEnoXsT5uKefRKX9PuvwbttN5Vc7Me57aPX9dReiBji4HgBVMI22gcugZ8mBTuNIecYNAAxiVcZjUFQ="}

      在开发商户会员卡发放卡券的时候,一直报 “无效的令牌”,很是郁闷,最后与支付宝相关技术定位问题,在于他们的文档未写完全,授权获取 access_token 时 scope 必须填写 auth_ecard

详见商户会员卡快速接入:

https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7386797.0.0.aUd2uI&treeId=251&articleId=105731&docType=1


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  支付宝 会员卡