PHP version of micro-letter public number interface to achieve the method of red envelopes _php skills

Source: Internet
Author: User
Tags openid

This article describes the PHP version of micro-letter public number interface to achieve the method of red envelopes. Share to everyone for your reference, specific as follows:

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

Micro-letter merchant number, has applied for micro-letter payment

The micro-letter public 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.

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

*
* * * * The micro-credit 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, the recipient of red envelopes can not be empty";
}
  $INPUTOBJ->setparameter (' Re_openid ', $re _openid); The user's OpenID
  $inputObj->setparameter (' Send_name ', "Auto parts Shop");//Red envelope sender name
  $inputObj->setparameter (' Total_amount ', "100"); The amount of the user receiving the red envelope is accurate to the
  $inputObj->setparameter (' Total_num ', "1");//The number of packets received
  $INPUTOBJ->setparameter (' Wishing ', "Congratulations to the rich, thank you for your support, small mind"); The user's OpenID
  $inputObj->setparameter (' client_ip ', "121.40.157.243");//Call the IP $inputObj of the interface
  -> Setparameter (' Act_name ', "Little Deng Thanksgiving Red envelope"); The red envelope theme
  $INPUTOBJ->setparameter (' remark ', "Thank you for your support");//remark
  $response = $INPUTOBJ->getresult ();
  return $response;
}

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

/** * Micro-letter Red Envelopes Interface **/class Sendredpack_pub extends Wxpay_client_pub {function __construct () {
  Set interface link $this->url = "Https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
Set Curl Timeout $this->curl_timeout = wxpayconf_pub::curl_timeout; /** * Generate interface parameter XML/function Createxml () {try {$this->parameters["mch_billno"] = Wxpayconf_pub::mchid.createuni Que ()//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 ());
  }/** * Effect: 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, the 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 errors.

For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.