PHP version of the micro-letter public number interface to send red envelopes program code

Source: Internet
Author: User
Tags openid
Recently received a task, need to use micro-letter to give users automatic red envelopes. To complete this task it is necessary to have some material
    1. Micro-letter merchant number, has applied for micro-letter payment
    2. The micro-letter number below the main body of the micro-letter merchant number

Look at the effect chart first

You just need to finish the following steps.

Deploy a red envelope code on a micro-mail-paid server

Call the red Envelope code on the micro-mail public number server

/*
* * Micro-letter Red envelope function
*/

Public Function Sendredpack () {

$re _openid = $this->_pg (' Re_openid ');
$INPUTOBJ = new Sendredpack_pub ();

if (! $re _openid) {
Return "micro-letter Red envelope function, receive red envelope users can not be empty";
}

$INPUTOBJ->setparameter (' Re_openid ', $re _openid); OpenID for users who receive red envelopes
$INPUTOBJ->setparameter (' Send_name ', "Auto parts shop"); Name of the sender of the red envelope
$INPUTOBJ->setparameter (' Total_amount ', "100"); The amount of the user receiving the red envelope, accurate to the point
$INPUTOBJ->setparameter (' Total_num ', "1"); Number of red envelopes received
$INPUTOBJ->setparameter (' Wishing ', "congratulate the rich, thank you for supporting, small Mind"); OpenID for users who receive red envelopes
$INPUTOBJ->setparameter (' client_ip ', "121.40.157.243"); Calling an interface's IP
$INPUTOBJ->setparameter (' Act_name ', "Little Deng Thanksgiving Red envelope"); Red Envelopes Theme
$INPUTOBJ->setparameter (' remark ', "Thank you for your support"); Note
$response = $INPUTOBJ->getresult ();

return $response;
}

Add a class to the micro-credit Payment Assistance tool layer to complete the bonus function


/**
* Micro-letter Hair Red Envelope interface
**/
Class Sendredpack_pub extends Wxpay_client_pub
{
function __construct () {
Setting Interface Links
$this->url = "Https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
Set the Curl timeout time
$this->curl_timeout = wxpayconf_pub::curl_timeout;
}

/**
* Generate interface parameter XML
*/
function Createxml ()
{
Try
{
$this->parameters["Mch_billno"] = Wxpayconf_pub::mchid.createunique ()//Merchant order number
$this->parameters["wxappid"] = wxpayconf_pub::appid;//public Account ID
$this->parameters["mch_id"] = wxpayconf_pub::mchid;//Merchant number
$this->parameters["nonce_str"] = $this->createnoncestr ();//random string
$this->parameters["sign"] = $this->getsign ($this->parameters);//Signature
return $this->arraytoxml ($this->parameters);
}catch (Sdkruntimeexception $e) {
Die ($e->errormessage ());
}
}

/**
* Role: Get results, use certificate communication
*/
function GetResult ()
{
$this->postxmlssl ();
$this->result = $this->xmltoarray ($this->response);
return $this->result;
}
}

Then deploy back to the micro-letter payment services above, it can!! Then add "red envelopes" to the service of the micro-credit public number (the public number). We can get to the top effect.

Develop according to the document
Please read the interface document carefully, refer to the document for development, please note that in order to ensure the safety of merchant funds, the interface is strong check the binding between merchant number and AppID, and the corresponding relationship between AppID and OpenID (if there is no binding between merchant number and AppID, That is, AppID did not apply for micro-letter payment or to apply for micro-letter payment merchant number mismatch, or OpenID attribution AppID error, the interface will return the errors)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.